-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongpriority-1-normalsemantic-analyzerProblems that happen during semantic analysisProblems that happen during semantic analysistopic-import-cycles
Description
This test case produces unexpected output when using the new semantic analyzer (after having reversed the processing order of modules within SCCs):
[case testAttributeDefOrder1]
import a
[file a.py]
from b import C
class D(C):
def g(self) -> None:
self.x = '' # Error (as expected)
def f(self) -> None:
reveal_type(self.x) # Revealed type is 'Any'; cannot determine type of 'x' (bad)
[file b.py]
import a
class C:
def __init__(self) -> None:
self.x = 0
I'd expect the type of x
to be consistently int
.
This test case produces unexpected output with both semantic analyzers:
[case testAttributeDefOrder2]
class D(C):
def g(self) -> None:
self.x = '' # No error here (should be an error)
def f(self) -> None:
reveal_type(self.x) # str (should be int)
class C:
def __init__(self) -> None:
self.x = 0
class E(C):
def g(self) -> None:
self.x = '' # Error here
def f(self) -> None:
reveal_type(self.x) # int
The reason for the weird behavior seems to be that we create duplicate Var
nodes for attributes if the methods of a subclass are processed before base class methods.
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongpriority-1-normalsemantic-analyzerProblems that happen during semantic analysisProblems that happen during semantic analysistopic-import-cycles