Skip to content

Commit 6a4f99a

Browse files
authored
Add test case for class variable forward reference (#6974)
This is broken with the old semantic analyzer but works with the new semantic analyzer. Closes #4760.
1 parent f8b59b4 commit 6a4f99a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

test-data/unit/check-newsemanal.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,3 +2461,13 @@ x: C
24612461
reveal_type(x) # E: Revealed type is '__main__.C[Any]'
24622462
[out]
24632463
[out2]
2464+
2465+
[case testNewAnalyzerClassVariableOrdering]
2466+
def foo(x: str) -> None: pass
2467+
2468+
class Something:
2469+
def run(self) -> None:
2470+
foo(self.IDS[0]) # E: Argument 1 to "foo" has incompatible type "int"; expected "str"
2471+
2472+
IDS = [87]
2473+
[builtins fixtures/list.pyi]

test-data/unit/fine-grained.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8969,3 +8969,26 @@ class B: ...
89698969
[builtins fixtures/list.pyi]
89708970
[out]
89718971
==
8972+
8973+
[case testClassVariableOrderingRefresh]
8974+
# flags: --new-semantic-analyzer
8975+
from b import bar
8976+
8977+
def foo(x: str) -> None: pass
8978+
8979+
class Something:
8980+
def run(self) -> None:
8981+
bar()
8982+
foo(self.IDS[0])
8983+
8984+
IDS = [87]
8985+
8986+
[file b.py]
8987+
def bar() -> int: return 0
8988+
[file b.py.2]
8989+
def bar() -> str: return '0'
8990+
[builtins fixtures/list.pyi]
8991+
[out]
8992+
main:9: error: Argument 1 to "foo" has incompatible type "int"; expected "str"
8993+
==
8994+
main:9: error: Argument 1 to "foo" has incompatible type "int"; expected "str"

0 commit comments

Comments
 (0)