-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
(🐞) 1.7 regression, (x: int)
considered a valid subtype of (*args: Any)
#16569
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
Comments
That error seems correct. The protocol demands that the function take any number of arguments. A callable that takes exactly one argument is not compatible. |
@JelleZijlstra Intuitively, I thought the same thing, but I think this is intentional, when it is not the subject of protocol compatability, mypy likes this subtype: # mypy: disable-error-code=empty-body
from __future__ import annotations
from typing import Any, Protocol
class A(Protocol):
def __call__(self, *args: Any) -> None: ...
class B(A):
def __call__(self, x: int) -> None: ... # no error
a: A = B() # no error Although, it could be that this is the defective behavior... See Lines 1597 to 1607 in 1200d1d
|
Jelle's analysis above is correct. Mypy is correct in emitting an error in the first code sample because protocol
Yes, I think this is a false negative. This should be flagged as an incompatible method override. For comparison, pyright emits an error here. The justification provided in the comment seems weak. This introduces a hole in the type system. Likewise, I don't think it's correct to consider These would be good points to discuss and clarify in the context of the typing spec shepherded by the newly-formed typing council (TC). |
Procotol
compatability for __call__
methods are broken for a *args: Any
signature(x: int)
considered a valid subtype of (*args: Any)
Ah yes, after some investigation, it appears that this is an unintended regression in 1.7, although all versions of mypy since 0.980 consider this as valid: from typing import Any
class Base:
def f(self, *args: Any, **kwargs: Any) -> None: ...
class Derived(Base):
def f(self, x: int) -> None: ... # no error |
@ilevkivskyi Was this closed as it is working as intended? if so, could you comment on the second example in the OP. |
Regarding the previous comment / whether |
See:
mypy/mypy/subtypes.py
Lines 1597 to 1607 in 1200d1d
This is inconsistent with how
(*args: Any, **kwargs: Any)
works:@ilevkivskyi
Protocol
compatibility ofUnpack
edTypeVarTuple
is broken when signature is not a trivial*args: Any
#16567The text was updated successfully, but these errors were encountered: