ruff/resources/test/fixtures/flake8_annotations
Charlie Marsh 403a004e03
Refactor import-tracking to leverage existing AST bindings (#1856)
This PR refactors our import-tracking logic to leverage our existing
logic for tracking bindings. It's both a significant simplification, a
significant improvement (as we can now track reassignments), and closes
out a bunch of subtle bugs.

Though the AST tracks all bindings (e.g., when parsing `import os as
foo`, we bind the name `foo` to a `BindingKind::Importation` that points
to the `os` module), when I went to implement import tracking (e.g., to
ensure that if the user references `List`, it's actually `typing.List`),
I added a parallel system specifically for this use-case.

That was a mistake, for a few reasons:

1. It didn't track reassignments, so if you had `from typing import
List`, but `List` was later overridden, we'd still consider any
reference to `List` to be `typing.List`.
2. It required a bunch of extra logic, include complex logic to try and
optimize the lookups, since it's such a hot codepath.
3. There were a few bugs in the implementation that were just hard to
correct under the existing abstractions (e.g., if you did `from typing
import Optional as Foo`, then we'd treat any reference to `Foo` _or_
`Optional` as `typing.Optional` (even though, in that case, `Optional`
was really unbound).

The new implementation goes through our existing binding tracking: when
we get a reference, we find the appropriate binding given the current
scope stack, and normalize it back to its original target.

Closes #1690.
Closes #1790.
2023-01-13 20:39:54 -05:00
..
allow_nested_overload.py Refactor import-tracking to leverage existing AST bindings (#1856) 2023-01-13 20:39:54 -05:00
allow_overload.py Avoid flagging ANN errors in @overload implementations (#1110) 2022-12-06 12:46:38 -05:00
allow_star_arg_any.py Implement ANN401 (#657) 2022-11-08 09:49:44 -05:00
annotation_presence.py Implement ANN401 (#657) 2022-11-08 09:49:44 -05:00
mypy_init_return.py Implement flake8-annotations (#625) 2022-11-06 17:25:49 -05:00
suppress_dummy_args.py Implement flake8-annotations (#625) 2022-11-06 17:25:49 -05:00
suppress_none_returning.py Implement flake8-annotations (#625) 2022-11-06 17:25:49 -05:00