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
Are you reporting a bug, or opening a feature request?
Bug
Please insert below the code you are checking with mypy.
importoperatorfromfunctoolsimportpartialmethodclassIntCmp:
def__init__(self, value):
self._value=valuedef_cmp(self, opr, other: int) ->bool:
ifisinstance(other, int):
returnopr(self._value, other)
returnNotImplemented__eq__=partialmethod(_cmp, operator.eq) # Incompatible types in assignment (expression has type "partialmethod[bool]", base class "object" defined the type as "Callable[[object, object], bool]")__ne__=partialmethod(_cmp, operator.ne) # Incompatible types in assignment (expression has type "partialmethod[bool]", base class "object" defined the type as "Callable[[object, object], bool]")# rest of the comparison operators (lt, le, gt, ge) type checks correctlyc=IntCmp(1)
assertc==1# Cannot determine type of '__eq__'
What is the actual behavior/output?
MyPy reports an error on the comparison, saying Cannot determine type of '__eq__', as well as incompatible types on assignment as shown.
The code correctly passes at runtime.
Yeah, it looks like no specific support for partialmethod is in mypy. I expect it to be a bit more complicated than partial support because partialmethod works with descriptors, but I'll have to think about how much more work it would be.
Bug
MyPy reports an error on the comparison, saying
Cannot determine type of '__eq__'
, as well as incompatible types on assignment as shown.The code correctly passes at runtime.
__eq__
and__ne__
should correctly type-check thepartialmethod
, and comparison should give no error. This particularpartialmethod
usage is shown in Python docs: https://docs.python.org/3/library/functools.html#functools.partialmethodDo you see the same issue after installing mypy from Git master?
Using latest git master, Python 3.8.1
EDIT: I am aware of #2967 and #1484 being a thing, however this covers
partialmethod
usage which wasn't mentioned as a topic in the two other issues.The text was updated successfully, but these errors were encountered: