-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-overloadstopic-protocolstopic-self-typesTypes for selfTypes for self
Description
overload with a self annotation involving a protocol never get matched:
class Proto[A_contra](Protocol):
def __call__(self, arg: A_contra, /) -> None: ...
class Fn:
def __call__(self, arg: int, /) -> None:
pass
@dataclass(frozen=True)
class Testclass[T_co]:
val: T_co
# this overload is problematic
@overload
def meth[T2](self: Testclass[Proto[T2]], arg: T2) -> int: ...
@overload
def meth(self, arg: None) -> str: ...
def meth(self: Any, *args, **kwargs):
return self.val
def fn(x: Testclass[Fn]):
# error: No overload variant of "meth" of "Testclass" matches argument type "int" [call-overload]
# note: Possible overload variant:
# note: def meth(self, arg: None) -> str
x.meth(5)it works fine if it is not an overload, or if using Callable rather than Proto.
https://mypy-play.net/?mypy=latest&python=3.12&gist=39ec9991c68ca9ed50f149359459e858
this works fine in pyright.
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-overloadstopic-protocolstopic-self-typesTypes for selfTypes for self