`F821` does not understand the intention of the following code
Closed
question
- Dominant language
- Rust
- Stars
- 49.6k
- Forks
- 2.4k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 445
Description
### Summary
```python
TYPE_CHECKING = False
if TYPE_CHECKING:
import typing
else:
typing = None
x: typing.Literal["a"] # produces F821: "a" is not defined
```
### Version
ruff 0.16.7 (b5dba861c 2026-09-10)
Contributor guide
Research direction
Start by reproducing the reported snippet with Ruff 0.16.7 and inspect the F821 diagnostic path for Python annotations and TYPE_CHECKING branches. Identify the existing tests covering undefined names or annotations, then add coverage for this example; done means the snippet no longer produces a spurious F821 for the string literal.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100