Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion mypy/server/aststripnew.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
58 changes: 58 additions & 0 deletions test-data/unit/fine-grained.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]
==