Commit graph

117 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
Zsolt Dollenstein
660e533610
Don't allow out of order accesses in the global scope (#431) 2020-12-15 20:46:15 +08:00
Zsolt Dollenstein
5940211af5
Handle scope ordering in For statements (#430)
* Handle scope ordering in For statements

* no need to increment after For anymore
2020-12-15 16:58:56 +08:00
Germán Méndez Bravo
2f117f0bc3
Fix for not parsing subscripts such as cast()["from"] (#428) 2020-12-08 09:48:09 +08:00
Zsolt Dollenstein
1326a0ee64
fix assignment/access ordering in comprehensions (#423) 2020-12-01 13:01:29 +00:00
Germán Méndez Bravo
2485d5a967
[Scope] Fix referencing of remaining objects in cast() (#422) 2020-11-30 12:50:23 +08:00
Germán Méndez Bravo
110095148f
Handle string type references in cast() (#418)
* Handle string type references in cast()

* Directly visit the first argument of cast()

Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>

Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
2020-11-17 18:55:44 +00:00
Zsolt Dollenstein
2ef730292b
[scope] keep track of assignment/access ordering (#413) 2020-11-17 17:40:50 +00:00
Zsolt Dollenstein
dd521f51e2
[scope] Visit concatenated f-strings (#411)
This PR makes sure scope analysis visits nodes under a ConcatenatedString.
2020-11-06 10:32:29 +00:00
luciawlli
a1b1ae45d5
Add Access.is_type_hint for types used in classdef base and assignment values (#406) 2020-10-28 11:48:06 +00:00
Germán Méndez Bravo
21d37b94b2
Support string annotations for type aliases (#401) 2020-10-12 11:12:28 -07:00
Jimmy Lai
7ca738bf39
Upgrade dev tools (Black/Flake8/isort) and read install requirements from requirements.txt (#380)
* Read install requirements from requirements.txt

* read extras_require from requirements-dev.txt

* add requirements-dev.txt to MANIFEST.in

* apply fixes for new version of Black and Flake8

* don't upgrade Pyre

* re-format
2020-08-31 10:44:55 -07:00
Germán Méndez Bravo
6f915ab39b
Literal could be imported from typing_extensions too (#375)
Co-authored-by: Germán Méndez Bravo <kronuz@fb.com>
2020-08-14 15:32:12 -07:00
Germán Méndez Bravo
fa15c980ef Handle string annotations in ScopeProvider 2020-08-14 14:59:22 -07:00
Germán Méndez Bravo
85761b2582 Add is_annotation subtype for Access inreferences.
Access references with this type come from an annotation.

(cherry picked from commit 39427eaabce9dff949ccc3545fc4a5d7a2d10930)
2020-08-14 08:22:48 -07:00
Germán Méndez Bravo
3e66bdd957 Fix enclosing attribute for attributes in call arguments
Fixes enclosed arguments like `c.d` in `x.y(c.d()).z()` were badly being
resolved as `x.y` instead.

This also clarifies the intent in `infer_accesses()` so it no longer shadows
variable `name` and also fixes the case where no node is actually found
in the scope.
2020-08-07 08:17:08 -07:00
Germán Méndez Bravo
2e8a0c6df7
Fix dotted names (#358)
## Summary

When importing things like `import os.path` and using it as `os.path.join("a", "b").lower()`,
references ended up being in the `["os"]` assignment instead of `["os.path"]`.
This fixes the problem by updating the dotted names generator in the scope provider·

## Test Plan

```
tox -e py37
```

Co-authored-by: Germán Méndez Bravo <kronuz@fb.com>
2020-08-04 17:33:22 -07:00
Jimmy Lai
eb761c2c67
[scope] add scope for ImportAlias (#350) 2020-07-28 08:58:59 -07:00
jimmylai
0870e41a79
[scope] add scope for ClassDef.name node (#349)
Co-authored-by: Jimmy Lai <jimmylai@fb.com>
2020-07-24 11:25:09 -07:00
lrjball
2d56ba7a3e
Minor typo in scope_provider.py (#324)
Fixed minor typo ('as'  was repeated)
2020-06-28 17:15:19 -07:00
jimmylai
c023fa7c4c
[typing] enable Pyre strict mode by default (#313)
Co-authored-by: Jimmy Lai <jimmylai@fb.com>
2020-06-12 18:24:18 -07:00
Josie Eshkenazi
cc7bb9db14
Add maxsplit value in QualifiedName retrieval (#312)
Maxsplit value to account for repeated letters in a QualifiedName
2020-06-11 12:04:10 -04:00
jimmylai
b9d4629f91
[scope] remove iter call to be efficient (#302)
Co-authored-by: Jimmy Lai <jimmylai@fb.com>
2020-05-28 09:07:30 -07:00
Zsolt Dollenstein
f32389a126
Fix StopIteration exception during scope analysis (#298)
During scope analysis all attribute accesses are collected for matching on
import names. The matching code (specifically `_gen_dotted_names`) was not
prepared for all types of expressions. In particular, complex expressions like
`foo[0].bar.baz()` caused a `StopIteration` exception when `_gen_dotted_names`
calls itself recursively. The nested call doesn't yield any values, and so
calling `next()` on it raises.

This commit fixes these types of errors.
2020-05-27 16:39:30 -07:00