Skip to content
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

False positive for overriding decorated method in an import cycle #5548

Closed
ilevkivskyi opened this issue Aug 31, 2018 · 0 comments
Closed

False positive for overriding decorated method in an import cycle #5548

ilevkivskyi opened this issue Aug 31, 2018 · 0 comments
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-import-cycles

Comments

@ilevkivskyi
Copy link
Member

Consider this test:

[case testCyclicDecoratir]
import b
[file a.py]
import b
import c

class A(b.B):
    @c.deco
    def meth(self) -> int: ...
[file b.py]
import a
import c

class B:
    @c.deco
    def meth(self) -> int: ...
[file c.py]
from typing import TypeVar, Tuple, Callable
T = TypeVar('T')
def deco(f: Callable[..., T]) -> Callable[..., Tuple[T, int]]: ...
[out]

It currently fails with

tmp/a.py:6: error: Signature of "meth" incompatible with supertype "B"

Although it is obviously compatible (it is actually identical). The error goes away if I change the order files are processed in the cycle (by importing a in main).

The reason is that non-trivial decorator needs to be type-checked to find the type in superclass first. A potential solution is to just defer the subclass method node.

@ilevkivskyi ilevkivskyi added bug mypy got something wrong priority-1-normal false-positive mypy gave an error on correct code labels Aug 31, 2018
@ilevkivskyi ilevkivskyi changed the title False negative for overriding decorated method in an import cycle False positive for overriding decorated method in an import cycle Aug 31, 2018
@ilevkivskyi ilevkivskyi mentioned this issue Sep 5, 2018
12 tasks
ilevkivskyi added a commit that referenced this issue Sep 20, 2018
Fixes #5560 
Fixes #5548 

Half of the PR is updating various function signatures to also accept `Decorator`. I still prohibit `Decorator` as a target in fine-grained mode, but I think there should be no harm to defer it in normal mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-import-cycles
Projects
None yet
Development

No branches or pull requests

1 participant