Skip to content

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

@ilevkivskyi

Description

@ilevkivskyi

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions