F821 with Annotated import alias
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 190
- Avg merge
- 8m
- Merged PRs (30d)
- 13
Description
We have a use-case where we sometimes import Annotated under a different name (since there is a naming collision with an existing object callled Annotations and Annotated[Annotations, ...] can be hard to read. Unfortunately, it looks like if we try to do this, then we fail with a false positive:
from typing_extensions import Annotated as WithSchema
def f(x: WithSchema[int, "hello"]) -> None:
return
fails pyflakes with F821 undefined name 'hello.
Everything works fine if we do not use the Annotated as WithSchema import alias though. Would it be possible to extend the logic to also handle such a case?
cc @nishkakar @ezrilow
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source files or tests are named in the issue. First reproduce the F821 warning with the provided Annotated as WithSchema example, then trace pyflakes' handling of Annotated imports and aliases. Done means the aliased example no longer reports the string literal as an undefined name while existing behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100