Commit 1918c61
authored
[red-knot] class bases are not affected by __future__.annotations (#17456)
## Summary
We were over-conflating the conditions for deferred name resolution.
`from __future__ import annotations` defers annotations, but not class
bases. In stub files, class bases are also deferred. Modeling this
correctly also reduces likelihood of cycles in Python files using `from
__future__ import annotations` (since deferred resolution is inherently
cycle-prone). The same cycles are still possible in `.pyi` files, but
much less likely, since typically there isn't anything in a `pyi` file
that would cause an early return from a scope, or otherwise cause
visibility constraints to persist to end of scope. Usually there is only
code at module global scope and class scope, which can't have `return`
statements, and `raise` or `assert` statements in a stub file would be
very strange. (Technically according to the spec we'd be within our
rights to just forbid a whole bunch of syntax outright in a stub file,
but I kinda like minimizing unnecessary differences between the handling
of Python files and stub files.)
## Test Plan
Added mdtests.1 parent 44ad201 commit 1918c61
File tree
2 files changed
+26
-7
lines changed- crates/red_knot_python_semantic
- resources/mdtest/annotations
- src/types
2 files changed
+26
-7
lines changedLines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
585 | 585 | | |
586 | 586 | | |
587 | 587 | | |
588 | | - | |
589 | | - | |
| 588 | + | |
| 589 | + | |
590 | 590 | | |
591 | 591 | | |
592 | 592 | | |
| |||
1467 | 1467 | | |
1468 | 1468 | | |
1469 | 1469 | | |
1470 | | - | |
| 1470 | + | |
1471 | 1471 | | |
1472 | 1472 | | |
1473 | 1473 | | |
| |||
1791 | 1791 | | |
1792 | 1792 | | |
1793 | 1793 | | |
1794 | | - | |
1795 | | - | |
1796 | | - | |
| 1794 | + | |
1797 | 1795 | | |
1798 | 1796 | | |
1799 | 1797 | | |
| |||
2919 | 2917 | | |
2920 | 2918 | | |
2921 | 2919 | | |
2922 | | - | |
| 2920 | + | |
2923 | 2921 | | |
2924 | 2922 | | |
2925 | 2923 | | |
| |||
0 commit comments