You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When declaring a protocol it is suggested in the documentation that method that have to be defined in implementations of that protocol can be marked with ... and I find this syntax quite pretty. However, currently the ... is treated as a default implementation. Which can lead to confusing behavior. An example is the following:
Given the rather drastic misspelling of add as subtract, mypy still infers the protocol to be correctly implemented. The result of reveal_type(z) is int, while it is actually NoneType. PEP 544 recommends to decorate non-default implementations with @abstractmethod. However, this leads to less elegant code and additional runtime checks. Since it seems kind of obvious that ... is never a default implementation of a method, I would suggest to treat it the same way as protocol methods decorated with @abstractmethod.
I am using mypy version 0.761.
The text was updated successfully, but these errors were encountered:
When declaring a protocol it is suggested in the documentation that method that have to be defined in implementations of that protocol can be marked with
...
and I find this syntax quite pretty. However, currently the...
is treated as a default implementation. Which can lead to confusing behavior. An example is the following:Given the rather drastic misspelling of
add
assubtract
, mypy still infers the protocol to be correctly implemented. The result ofreveal_type(z)
isint
, while it is actuallyNoneType
. PEP 544 recommends to decorate non-default implementations with@abstractmethod
. However, this leads to less elegant code and additional runtime checks. Since it seems kind of obvious that...
is never a default implementation of a method, I would suggest to treat it the same way as protocol methods decorated with@abstractmethod
.I am using mypy version
0.761
.The text was updated successfully, but these errors were encountered: