F401 false positive for forward references in TypeAliases
- Dominant language
- Rust
- Stars
- 49.6k
- Forks
- 2.4k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 414
Description
### Summary
When using forward references on the right hand side of the `=` in a type alias, ruff considers the types used in that forward reference unused and issues a F401. Interestingly, the `"TypeAlias"` import does not cause an issue because it's used in an annotation.
https://play.ruff.rs/e30129f9-c09c-4c76-9272-9aa757ece49b
It seems that ruff needs to be aware of type aliases and treat the right side as uses. While this isn't possible for implicit aliases (where `TypeAlias` is *not* used in the annotation of the alias), it is possible for explicit aliases.
### Version
0.11.6
Contributor guide
Research direction
Start with the linked Ruff Playground reproduction and trace how explicit TypeAlias assignments are analyzed for F401. Confirm the current behavior against Ruff version 0.11.6, then verify that types referenced on the right-hand side of an explicit alias are treated as used without changing the existing TypeAlias import behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100