From fb551466ba7780e1421c28abd88f576d2bbe5d6c Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Thu, 27 Jun 2019 17:08:21 +0100 Subject: [PATCH 1/2] Add tests --- test-data/unit/fine-grained.test | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) 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] +== From 011607e09ce0befb935f34217a963f1bb0d58539 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Thu, 27 Jun 2019 17:53:40 +0100 Subject: [PATCH 2/2] Quick and dirty fix for nested classes in fine grained mode --- mypy/server/aststripnew.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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: