Skip to content

Commit

Permalink
Add test case for class variable forward reference (python#6974)
Browse files Browse the repository at this point in the history
This is broken with the old semantic analyzer but works with the new
semantic analyzer.

Closes python#4760.
  • Loading branch information
JukkaL authored Jun 13, 2019
1 parent f8b59b4 commit 6a4f99a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test-data/unit/check-newsemanal.test
Original file line number Diff line number Diff line change
Expand Up @@ -2461,3 +2461,13 @@ x: C
reveal_type(x) # E: Revealed type is '__main__.C[Any]'
[out]
[out2]

[case testNewAnalyzerClassVariableOrdering]
def foo(x: str) -> None: pass

class Something:
def run(self) -> None:
foo(self.IDS[0]) # E: Argument 1 to "foo" has incompatible type "int"; expected "str"

IDS = [87]
[builtins fixtures/list.pyi]
23 changes: 23 additions & 0 deletions test-data/unit/fine-grained.test
Original file line number Diff line number Diff line change
Expand Up @@ -8969,3 +8969,26 @@ class B: ...
[builtins fixtures/list.pyi]
[out]
==

[case testClassVariableOrderingRefresh]
# flags: --new-semantic-analyzer
from b import bar

def foo(x: str) -> None: pass

class Something:
def run(self) -> None:
bar()
foo(self.IDS[0])

IDS = [87]

[file b.py]
def bar() -> int: return 0
[file b.py.2]
def bar() -> str: return '0'
[builtins fixtures/list.pyi]
[out]
main:9: error: Argument 1 to "foo" has incompatible type "int"; expected "str"
==
main:9: error: Argument 1 to "foo" has incompatible type "int"; expected "str"

0 comments on commit 6a4f99a

Please sign in to comment.