Commit graph

232 commits

Author SHA1 Message Date
Ken Kawamoto
7090a0db2b
fixes match statements to work with PositionProvider (#1389)
* add failing test

* fix issue

* fixes an issue with PositionProvider not working with case statement

* remove comments

---------

Co-authored-by: steve <steve@patreon.com>
2025-08-04 17:27:13 -04:00
martin
9542fc3882
remove entry points to pure parser (#1375)
* rm: ci

* rm: entry point

* fix: tests

* fix: remove combine step from ci

* linter fixes

* omit the _parser

* fix newlines

* fix: remove optional

* fix: linter

---------

Co-authored-by: thereversiblewheel <martin.li@uwaterloo.ca>
2025-07-30 16:27:20 +00:00
zaicruvoir1rominet
ca1f81f049
Avoid raising bare Exception (#1168)
* Keep old exception messages (avoid breaking-changes for users relying on exception messages)

* Move ``get_expected_str`` out of _exceptions.py, where it does not belong, to its own file in _parser/_parsing_check.py
2025-06-07 01:53:44 -07:00
dependabot[bot]
be0b668d08
Bump black from 24.8.0 to 25.1.0 (#1290)
* Bump black from 24.8.0 to 25.1.0

Bumps [black](https://github.com/psf/black) from 24.8.0 to 25.1.0.
- [Release notes](https://github.com/psf/black/releases)
- [Changelog](https://github.com/psf/black/blob/main/CHANGES.md)
- [Commits](https://github.com/psf/black/compare/24.8.0...25.1.0)

---
updated-dependencies:
- dependency-name: black
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fix formatting and tests

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Amethyst Reese <amethyst@n7.gg>
2025-05-19 20:53:44 -04:00
dependabot[bot]
bf5fb4132e
Bump black from 23.12.1 to 24.8.0 (#1186)
* Bump black from 23.12.1 to 24.8.0

Bumps [black](https://github.com/psf/black) from 23.12.1 to 24.8.0.
- [Release notes](https://github.com/psf/black/releases)
- [Changelog](https://github.com/psf/black/blob/main/CHANGES.md)
- [Commits](https://github.com/psf/black/compare/23.12.1...24.8.0)

---
updated-dependencies:
- dependency-name: black
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update formatting

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Amethyst Reese <amethyst@n7.gg>
2024-08-22 16:46:01 -07:00
Camillo
9f6e27600f
FullyQualifiedNameProvider: Optionally consider pyproject.toml files when determining a file's module name and package (#1148) 2024-06-12 10:36:50 +01:00
Zsolt Dollenstein
4fb66a33e6
remove mypy_extensions import (#1128) 2024-04-03 21:10:44 +01:00
Kyle Into
83f0daed42
fix filepathprovider generic type (#1036)
* fix filepathprovider type

* remove extra import
2023-10-05 20:18:39 -07:00
Sergii Dymchenko
7ca5d7f173
Fix link in type_inference_provider.py (#1035)
Same change as https://github.com/Instagram/LibCST/pull/913, but in the docstring.
2023-10-05 15:46:25 -07:00
André C. Silva
552af63d29
ScopeProvider: Record Access for Attributes and Decorators (#1019)
* Support for Attributes and Decorators in _NameUtil

* Replaced _NameUtil with get_full_name_for_node

* Added tests
2023-10-01 18:34:42 +01:00
Zsolt Dollenstein
46060119a4
Scope provider changes for type annotations (#1014) 2023-09-30 11:16:27 +01:00
Zsolt Dollenstein
9d869b6639
scope_provider: Simplify parent resolution (#1013)
This PR introduces `Scope._next_visible_parent` which deduplicates much of the logic between `_contains_in_self_or_parent`, `_find_assignment_target_parent`, and `_getitem_from_self_or_parent`.

This will be helpful when implementing scope resolution for the future `AnnotationScope`.

There should be no functionality change.
2023-09-16 03:59:29 -07:00
dependabot[bot]
46509dd5e1
Bump black from 22.12.0 to 23.1.0 (#860) 2023-03-15 11:53:50 +00:00
Amethyst Reese
c876db6d2d Add new FilePathProvider
Caches file path information on the root `Module` node.
Resolves paths when caching, so they are always absolute paths.

Adds a new `chdir` helper to change working directory and automatically
revert to previous directory, which makes testing file paths with the
`"."` repo root easier.

ghstack-source-id: 3413905fc1
Pull Request resolved: https://github.com/Instagram/LibCST/pull/892
2023-03-13 18:33:46 -07:00
Amethyst Reese
f9536b522f
Pass root path to FullyQualifiedNameProvider (#867)
This allows FullyQualifiedNameProvider to work with absolute paths,
rather than assuming all paths given will be relative to the current
directory. This enables tools like Fixit to provide a root path, and
have the FullyQualifiedNameProvider correctly scope the final results
relative to that root path.

This does require that both the root path and the given file paths
match the other as relative or absolute, due to the
`calculate_module_and_package` helper comparing file paths relative
to the root path, but this seems like a reasonable tradeoff, and
unlikely to cause a problem in normal use cases.
2023-02-22 14:36:10 -08:00
Amethyst Reese
d94687e378
Script to regenerate test fixtures (#872)
Upgrading Pyre requires updating test fixtures with any upstream changes
to Pyre's query results for the `simple_class.py` fixture.

This adds a new `scripts/` directory to the repo, with a script to
regenerate test fixtures. The script regenerates the cache data fixture,
and updates the `TypeInferenceProvider` tests to use `assertDictEqual`
and helpful error messages for better behavior in future mismatches.

This also includes a slight bump to Pyre 0.9.10 to fix install issues on
Apple Silicon M1 Macs, and regenerated fixtures using the script above.
2023-02-22 12:35:23 -08:00
Matthew Shaer
c44b182e88
Adding a provider which can tell what accessor to use to go from the parent to that child node (#807) 2022-11-10 09:38:32 +00:00
MapleCCC
64811b7795
Tighten the metadata type of ExpressionContextProvider (#760) 2022-08-29 16:46:08 +01:00
MapleCCC
73cfc7f7fa
Fix docstring of FullRepoManager (#750)
The render error originates from how we violate the syntax rules of the `field list` markup element of reStructuredText. The `specification of field list states](https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#field-lists) that a multi-line `field body` must be indented relative to the `field marker`.
2022-08-17 13:42:31 +01:00
Chenguang Zhu
7cb229d175
Implement lazy loading mechanism for QualifiedNameProvider (#720)
* Implement lazy loading mechanism for expensive metadata providers
* Add support for lazy values in metadata matchers
* Fix type issues and implement lazy value support in base metadata provider too
* Add unit tests for BaseMetadataProvider

Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
2022-07-09 08:34:29 +01:00
Luke Petre
b3eda508d4
Fixing prefix matching bug from 0.4.6 (#719) 2022-07-05 11:25:39 +01:00
Luke Petre
aa4a2790db
Remove unnecessary qname work (#709) 2022-06-21 21:35:05 +01:00
Luke Petre
779163701c
Faster qualified name format (#710) 2022-06-21 14:26:45 +01:00
Luke Petre
42164f8672
Cache the scope name prefix to prevent scope traversal in a tight loop (#708)
* Cache the scope name prefix to prevent scope traversal in a tight loop

* Adding pyre-fixme. this attribute iclearly has a type in the base class.

* Clarify why we do join(filter(None,...
2022-06-21 10:11:02 +01:00
Luke Petre
6f28c799bb
Fix slow perf in 0.4.2+ (#698) 2022-06-16 12:45:02 +01:00
Luke Petre
c6559671aa
Consider access information when computing qualified names for nodes (#682)
* Write a test case showing qualified names for shadowed assignments

* Consider accesses when looking up names of nodes

* Fix format

* Fix typecheck
2022-05-04 09:50:26 -04:00
wiyr
0a8ae91d39
fix qualified name get bug (#669)
* fix qualified name get bug

* added unittest
2022-04-08 08:25:15 -07:00
Luke Petre
cf16eccea4
Update relative import logic to match cpython (#660)
* Always compute a module and package name

* Update name_provider to correctly support __main__ (also updated the tests to use data_provider)

* Update name_provider to correctly handle relative imports and package name

* Update relative module resolution to work on package names

* Use full_package_name in libcst.codemod.visitors.GatherImportsVisitor

* Use full_package_name in libcst.codemod.visitors.RemovedNodeVisitor

* Use full_package_name in libcst.codemod.visitors.AddImportsVisitor

* Fix failing test

* Fix typo in variable name

* PR feedback

* Force rebuild
2022-03-24 17:21:08 -04:00
Stanislav Levin
bb6d150acd
tests: Fix assumption about sorting in test_ordering (#650)
The test wrongly assumed that `first_assignment.references`
is ordered collection, while actually it is `set`.

Fixes: https://github.com/Instagram/LibCST/issues/442
Signed-off-by: Stanislav Levin <slev@altlinux.org>
2022-02-18 09:10:56 -08:00
Zsolt Dollenstein
d9a1dc8473
Fix all type errors (#579)
* bump pyre version
* make sure CI-pyre uses working copy
* remove unused pyre suppressions
* suppress invalid decorations
* fix undefined attributes
* fix missing return annotations
* fix tuple concatenation issues
* add native stubs
* fix invalid typing of **kwargs in test_apply_type_annotations
* only install pyre on non-windows
* update test fixture to reflect changes in recent pyre versions
* suppress errors related to mismatched positions
2022-01-05 18:13:01 +00:00
Zsolt Dollenstein
c44ff0500b
Fix license headers (#560)
* Facebook -> Meta

* remove year from doc copyright
2021-12-28 11:55:18 +00:00
John Reese
10c3aa09a7
Upgrade to µsort 1.0.0rc1, and apply formatting changes (#565)
* Upgrade to usort==1.0.0rc1

* Apply sorting changes from usort 1.0.0rc1

* reapply codegen

Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
2021-12-21 14:55:04 -08:00
Luke Petre
58b447d8f7
Fixes incorrectly missing annotations (#561)
Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
2021-11-23 11:08:23 +00:00
Giorgi Megreli
c48cc2101a
Move find_qualified_names_for in the Assignment class. (#557)
Move _NameUtil.find_qualified_name_for ... method inside Assignment classes.
2021-11-19 14:58:50 +00:00
Giorgi Megreli
9732f5ec82
Correct and simplify logic of recording assignments (#556) 2021-11-19 07:21:06 -05:00
Giorgi Megreli
ae8d0cda2f
Pin accesses to import alias node (#554)
* Add ImportAssignment class and record it from Scope

* Add overrides for LocalScope and ClassScope

* Clean scope_provider code and use ImportAssignment class in `unusued_imports` codemod

* Add missing types

* Fix fixit errors
2021-11-19 11:20:47 +00:00
Luke Petre
463f15e805
Test overwriting imports w/ global and nonlocal stmts (#553) 2021-11-18 17:08:19 -05:00
Luke Petre
56386d7add
Stop parsing string annotations when no longer in a typing call (#546)
* Fix ScopeProvider when string type annotation is unparsable

* Handle nested function calls w/in type declarations

* Edit stack in place

* Add unparsed test to test_cast
2021-11-17 16:12:02 -05:00
Luke Petre
7db6ec5384
Swallow parsing errors in string annotations. (#548)
* Swallow parsing errors in string annotations.

This is the same behavior as cPython.

I've also rewritten the test that was relying on this exception to check where type parsing was happening

* Fix pyre error
2021-11-17 15:08:52 -05:00
Luke Petre
3dbcf5fed7
Don't gather metadata if the wrapper already contains it (#545)
Make sure that the MetadataWrapper to resolves the requested providers vs the existing metadata results and prevent a single provider from being invoked multiple times.
2021-11-08 15:34:24 -05:00
Rodrigo Zhou
683731b1e1
Fix pyre command for type inference provider (#523)
* Fix pyre command for type inference provider

* fix integration test

Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
2021-09-16 17:59:24 +01:00
Steven Troxler
5e1e3fe970
The ufmt tool combines usort and black with a consistent wrapper, (#515)
which ensures we won't have inconsistent black-vs-isort errors
going forward. We can always format by running `ufmt format .`
at the root, and check with `ufmt check .` in our CI actions.
2021-08-25 20:39:29 -04:00
Zsolt Dollenstein
4d2ccc54b2
tie accesses from string annotation to the string node (#483) 2021-05-12 14:50:15 +01:00
Bruno Alla
d1606b7077
Fix formatting for link to QualifiedName class in docs (#480) 2021-04-28 10:19:54 +01:00
Zsolt Dollenstein
3b21fa9da9
Return more specific QNames for assignments (#477)
When `scope.get_qualified_names_for()` is called with a node that's an `Assignment`, return the qualified name for that node instead of all the assignments for the same name.
2021-04-19 14:41:12 +01:00
Lisa Roach
068b90595f
Fixes TypeInferenceProvider breakage with empty cache. (#476)
* Fixes TypeInferenceProvider breakage with empty cache.
2021-04-08 08:33:32 +01:00
Lisa Roach
e759ca8290
Fix leaking processes from TypeInferenceProvider (#474)
* Switches to subprocess.run.

* Updates cmd to avoid string escaping.
2021-04-02 20:08:54 +01:00
Zsolt Dollenstein
1bd1c0890c
Add FullyQualifiedNameProvider (#465) 2021-03-26 17:15:57 +00:00
Luke Petre
4ab866e40f
Add BuiltinScope (#469)
* Add more builtin tests

* Introduce a BuiltinScope that sits above GlobalScope

* Address comments and fix lint

* Updating documentation

* Update scope illustration

* Add BuiltinScope to libcst.metadata

* Lazily create builtin assignments, update scope diagram
2021-03-24 12:12:56 -07:00
Zsolt Dollenstein
507b453e74
Split QualifiedNameProvider out from libcst.metadata.scope_provider (#464)
* Split QualifiedNameProvider out of scope_provider.py

* merge test_qualified_name_provider into test_name_provider
2021-03-12 10:10:44 +00:00