Skip to content

New semantic analyzer: infinite loop in daemon with decorators, nested classes #7073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
msullivan opened this issue Jun 26, 2019 · 6 comments · Fixed by #7085
Closed

New semantic analyzer: infinite loop in daemon with decorators, nested classes #7073

msullivan opened this issue Jun 26, 2019 · 6 comments · Fixed by #7085
Labels
bug mypy got something wrong priority-0-high semantic-analyzer Problems that happen during semantic analysis topic-fine-grained-incremental

Comments

@msullivan
Copy link
Collaborator

Minimized from an example reported by a user at dropbox.

[case testInfiniteLoop]
# Only happens with new analyzer???
# 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]
==

The issue seems to be that if a nested class isn't reprocessed and the toplevel gets reprocessed, it disappears from the symbol table and triggers its dependencies. If the toplevel depends on the nested class, then this can cause ping-ponging where the two nested classes alternate disappearing and reappearing.

The decorator and the method referencing the class are there because the create the needed dependencies.

@msullivan msullivan added bug mypy got something wrong topic-fine-grained-incremental semantic-analyzer Problems that happen during semantic analysis labels Jun 26, 2019
@msullivan
Copy link
Collaborator Author

Another related case with NamedTuple

[case testInfiniteLoop2]
# Only happens with new analyzer???
# 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]
==

@ilevkivskyi
Copy link
Member

This is essentially a duplicate of #6422 (see the last bullet about fine-grained mode). I can either add a hot fix, or we can try a more general fix.

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 27, 2019

How much work would a general fix be relative to a hot fix?

@ilevkivskyi
Copy link
Member

How much work would a general fix be relative to a hot fix?

It's hard to tell, by I think it may be 2-3 days, the refactoring of this area is quite overdue.

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 27, 2019

Let's plan for that separately and implement a quick fix for now.

@ilevkivskyi
Copy link
Member

OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-0-high semantic-analyzer Problems that happen during semantic analysis topic-fine-grained-incremental
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants