diff --git a/mypy/server/aststripnew.py b/mypy/server/aststripnew.py index 99fe228ef0c1..126751607f7b 100644 --- a/mypy/server/aststripnew.py +++ b/mypy/server/aststripnew.py @@ -62,7 +62,11 @@ def strip_file_top_level(self, file_node: MypyFile) -> None: self.recurse_into_functions = False file_node.plugin_deps.clear() file_node.accept(self) - file_node.names.clear() + for name in file_node.names.copy(): + # TODO: this is a hot fix, we should delete all names, + # see https://github.com/python/mypy/issues/6422. + if '@' not in name: + del file_node.names[name] def visit_block(self, b: Block) -> None: if b.is_unreachable: diff --git a/test-data/unit/fine-grained.test b/test-data/unit/fine-grained.test index 3ca3eec68e12..9a8301463fc7 100644 --- a/test-data/unit/fine-grained.test +++ b/test-data/unit/fine-grained.test @@ -8992,3 +8992,61 @@ def bar() -> str: return '0' 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" + +[case testInfiniteLoop] +# flags: --new-semantic-analyzer +[file a.py] +from b import f +from typing import Callable, TypeVar + +F = TypeVar('F', bound=Callable) +def dec(x: F) -> F: return x + +@dec +def foo(self): + class A: + @classmethod + def asdf(cls, x: 'A') -> None: pass + +@dec +def bar(self): + class B: + @classmethod + def asdf(cls, x: 'B') -> None: pass + f() + +[file b.py] +def f() -> int: pass +[file b.py.2] +def f() -> str: pass +[builtins fixtures/classmethod.pyi] +[out] +== + +[case testInfiniteLoop2] +# flags: --new-semantic-analyzer +[file a.py] +from b import f +from typing import Callable, TypeVar, NamedTuple + +F = TypeVar('F', bound=Callable) +def dec(x: F) -> F: return x + +@dec +def foo(self): + N = NamedTuple('N', [('x', int)]) + def g(x: N) -> None: pass + +@dec +def bar(self): + N = NamedTuple('N', [('x', int)]) + def g(x: N) -> None: pass + f() + +[file b.py] +def f() -> int: pass +[file b.py.2] +def f() -> str: pass +[builtins fixtures/classmethod.pyi] +[out] +==