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
It seems that mypy doesn't allow __ne__ returning NotImplemented, (this is allowed with __eq__).
And when I try explicitly adding NotImplemented as a possible return type, I get a run-time error:
File ".../pod.py", line 65, in PlainOldData
def __ne__(self, other: Any) -> Union[bool, NotImplemented]:
File "/usr/lib/python3.6/typing.py", line 682, in inner
return func(*args, **kwds)
File "/usr/lib/python3.6/typing.py", line 800, in __getitem__
parameters = tuple(_type_check(p, msg) for p in parameters)
File "/usr/lib/python3.6/typing.py", line 800, in <genexpr>
parameters = tuple(_type_check(p, msg) for p in parameters)
File "/usr/lib/python3.6/typing.py", line 374, in _type_check
raise TypeError(msg + " Got %.100r." % (arg,))
TypeError: Union[arg, ...]: each arg must be a type. Got NotImplemented.
If I change this to def __ne__(self, other: Any) -> Union[bool, type(NotImplemented)]:, then mypy complains:
error: invalid type comment or annotation
note: Suggestion: use type[...] instead of type(...)
and when I try using this suggestion, I get a runtime error:
TypeError: 'type' object is not subscriptable
@gvanrossum suggested (in issue 1101) that this was due to __ne__ not being in sharedparse.__MAGICMETHODS; but it does appear to be there.
Activity
gvanrossum commentedon Mar 20, 2018
But it's not in
BINARY_MAGIC_METHODS.kamahen commentedon Mar 20, 2018
Oops. I'll put together a PR.
Handle NotImplemented from __ne__ (#4770)