-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Description
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.
Metadata
Metadata
Assignees
Labels
No labels