File tree Expand file tree Collapse file tree 2 files changed +63
-1
lines changed Expand file tree Collapse file tree 2 files changed +63
-1
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,11 @@ def strip_file_top_level(self, file_node: MypyFile) -> None:
62
62
self .recurse_into_functions = False
63
63
file_node .plugin_deps .clear ()
64
64
file_node .accept (self )
65
- file_node .names .clear ()
65
+ for name in file_node .names .copy ():
66
+ # TODO: this is a hot fix, we should delete all names,
67
+ # see https://github.com/python/mypy/issues/6422.
68
+ if '@' not in name :
69
+ del file_node .names [name ]
66
70
67
71
def visit_block (self , b : Block ) -> None :
68
72
if b .is_unreachable :
Original file line number Diff line number Diff line change @@ -8992,3 +8992,61 @@ def bar() -> str: return '0'
8992
8992
main:9: error: Argument 1 to "foo" has incompatible type "int"; expected "str"
8993
8993
==
8994
8994
main:9: error: Argument 1 to "foo" has incompatible type "int"; expected "str"
8995
+
8996
+ [case testInfiniteLoop]
8997
+ # flags: --new-semantic-analyzer
8998
+ [file a.py]
8999
+ from b import f
9000
+ from typing import Callable, TypeVar
9001
+
9002
+ F = TypeVar('F', bound=Callable)
9003
+ def dec(x: F) -> F: return x
9004
+
9005
+ @dec
9006
+ def foo(self):
9007
+ class A:
9008
+ @classmethod
9009
+ def asdf(cls, x: 'A') -> None: pass
9010
+
9011
+ @dec
9012
+ def bar(self):
9013
+ class B:
9014
+ @classmethod
9015
+ def asdf(cls, x: 'B') -> None: pass
9016
+ f()
9017
+
9018
+ [file b.py]
9019
+ def f() -> int: pass
9020
+ [file b.py.2]
9021
+ def f() -> str: pass
9022
+ [builtins fixtures/classmethod.pyi]
9023
+ [out]
9024
+ ==
9025
+
9026
+ [case testInfiniteLoop2]
9027
+ # flags: --new-semantic-analyzer
9028
+ [file a.py]
9029
+ from b import f
9030
+ from typing import Callable, TypeVar, NamedTuple
9031
+
9032
+ F = TypeVar('F', bound=Callable)
9033
+ def dec(x: F) -> F: return x
9034
+
9035
+ @dec
9036
+ def foo(self):
9037
+ N = NamedTuple('N', [('x', int)])
9038
+ def g(x: N) -> None: pass
9039
+
9040
+ @dec
9041
+ def bar(self):
9042
+ N = NamedTuple('N', [('x', int)])
9043
+ def g(x: N) -> None: pass
9044
+ f()
9045
+
9046
+ [file b.py]
9047
+ def f() -> int: pass
9048
+ [file b.py.2]
9049
+ def f() -> str: pass
9050
+ [builtins fixtures/classmethod.pyi]
9051
+ [out]
9052
+ ==
You can’t perform that action at this time.
0 commit comments