{"id":21971162,"url":"https://github.com/squiddy/libcst_easy_matcher","last_synced_at":"2025-07-11T01:06:22.948Z","repository":{"id":142143930,"uuid":"252355024","full_name":"squiddy/libcst_easy_matcher","owner":"squiddy","description":"An experiment to create matchers from source code when working with LibCST","archived":false,"fork":false,"pushed_at":"2020-04-07T05:05:16.000Z","size":14,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T03:48:07.213Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/squiddy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-02T04:27:22.000Z","updated_at":"2024-03-01T17:32:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"7bc05b4a-db0b-45ee-b444-03d23e0227cc","html_url":"https://github.com/squiddy/libcst_easy_matcher","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squiddy%2Flibcst_easy_matcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squiddy%2Flibcst_easy_matcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squiddy%2Flibcst_easy_matcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squiddy%2Flibcst_easy_matcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/squiddy","download_url":"https://codeload.github.com/squiddy/libcst_easy_matcher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245031363,"owners_count":20549914,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-29T14:49:05.225Z","updated_at":"2025-03-22T22:46:04.848Z","avatar_url":"https://github.com/squiddy.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libcst_easy_matcher\n\nAn experiment to create matchers from source code when working with\n[LibCST](https://libcst.readthedocs.io/). A matcher enables you to check\nwhether a certain node in the tree generated by LibCST matches a certain\npattern.\n\n## Status\n\n```python\na = 3\na = __\n__ = 3\nb = bar(x=3)\nb = bar(x=__)\nb = __(x=3)\n```\n\nSee `tests/test_libcst_easy_matcher.py` for all examples.\n\n## Motivation\n\nIf I want to check that a statement matches \n\n```python\nclient[\"cookies\"] = get_cookie(request)\n```\n\nI'd write something like this:\n\n```python\nm.Assign(\n    targets=[\n        m.AssignTarget(\n            target=m.Subscript(\n                value=m.Attribute(\n                    value=m.Name(\"client\"),\n                    attr=m.Name(\"cookies\"),\n                )\n            )\n        )\n    ],\n    value=m.Call(\n        func=m.Name(\n            value='get_cookie'\n        ),\n        args=[\n            m.Arg(\n                value=m.Name(\n                    value='request'\n                )\n            )\n        ]\n    )\n)\n```\n\nI'm experimenting here to instead do it like this: \n\n```python\ncreate_matcher(\"client['cookies'] = get_cookie(request)\")\n```\n\n## Placeholders\n\nJust matching against concrete values only get's you so far, so I'm\nevaluating the use of placeholders like this:\n\n```python\n__ = get_cookie(request)\nclient[__] = get_cookie(request)\nclient['cookies'] = __(request)\nclient['cookies'] = get_cookie(__)\n```\n\nAll of which should match the example code. `__` might not be the best choice\nin the long run, but I needed a valid identifier to be able to still parse\nthe code with LibCST.\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquiddy%2Flibcst_easy_matcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsquiddy%2Flibcst_easy_matcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquiddy%2Flibcst_easy_matcher/lists"}