mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:35:58 +00:00

## Summary Given: ```python baz: Annotated[ str, [qux for qux in foo], ] ``` We treat `baz` as `BindingKind::Annotation`, to ensure that references to `baz` are marked as unbound. However, we were _also_ treating `qux` as `BindingKind::Annotation`, which meant that the load in the comprehension _also_ errored. Closes https://github.com/astral-sh/ruff/issues/7879.
21 lines
427 B
Python
21 lines
427 B
Python
"""Test bindings created within annotations under `__future__` annotations."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Annotated
|
|
|
|
foo = [1, 2, 3, 4, 5]
|
|
|
|
|
|
class Bar:
|
|
# OK: Allow list comprehensions in annotations (i.e., treat `qux` as a valid
|
|
# load in the scope of the annotation).
|
|
baz: Annotated[
|
|
str,
|
|
[qux for qux in foo],
|
|
]
|
|
|
|
|
|
# Error: `y` is not defined.
|
|
x: (y := 1)
|
|
print(y)
|