-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More precise type checking of NotImplemented and operator overloading #363
Comments
There is no |
because NoReturn is an alias for Any python/mypy#363
Could we please get some official guidance on how to workaround this issue in the short term? I understand the complexity at stake here after reading the referenced/referencing issues, but I think it'd be helpful to have an "official workaround" until this gets resolved. From my understanding, the problem is: def __eq__(self, other: Any) -> bool: ... # Doesn't work.
def __eq__(self, other: Any) -> Union[bool, NotImplemented]: ... # Doesn't work.
def __eq__(self, other: Any) -> Any: ... # Only option? |
Are there any updates on this? |
NotImplemented should be implicitly a valid return value of operator methods such as
__lt__
,__add__
, but it should be flagged as an error to return it elsewhere (unless, maybe, the return type includes a suitable type such as typing.NotImplementedType).Currently NotImplemented has type Any which allows it to be used in any context, which is wrong.
This should be fine:
This should not be fine:
The text was updated successfully, but these errors were encountered: