Optional keyword parameters vs overloads #1782
Unanswered
randolf-scholz
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Refer to this section of the typing spec for subtyping rules involving callables with overloads. Here's the relevant part:
In your example, this condition is not met. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was writing a protocol class for Array-like objects supporting a
round(self, *, decimals: int = 0) -> Self
operation. To my surprise, it didn't liketorch.Tensor
, which defines:Both mypy and pyright seem to agree that:
(self, *, decimals: int = 0) -> X
is a subtype ofOverload[(self) -> X, (self, *, decimals: int) -> X]
Overload[(self) -> X, (self, *, decimals: int) -> X]
is not a subtype of(self, *, decimals: int = 0) -> X
But to me, it seems these signatures are equivalent. Am I missing something, or is this a limitation of the type checkers?
Code sample in pyright playground mypy-playground
Beta Was this translation helpful? Give feedback.
All reactions