-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Do not handle NotImplementedType as Any anymore.
#20114
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
base: master
Are you sure you want to change the base?
Changes from 5 commits
4143846
39d56bf
9bb029f
df6418d
fb04bad
9b584b6
0aa07ea
a9c6318
0fc0efc
c04458c
d3957d0
aed1acd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6852,3 +6852,38 @@ if isinstance(headers, dict): | |
|
|
||
| reveal_type(headers) # N: Revealed type is "Union[__main__.Headers, typing.Iterable[tuple[builtins.bytes, builtins.bytes]]]" | ||
| [builtins fixtures/isinstancelist.pyi] | ||
|
|
||
| [case testReturnNotImplementedInBinaryMagicMethods] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you move this to check-overloading?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests were originally in the "Returning Any" section of
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd probably put them in
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is. But we may add many explicit overloads to them later... |
||
| from typing import Union | ||
| class A: | ||
| def __add__(self, other: object) -> int: | ||
| return NotImplemented | ||
| def __radd__(self, other: object) -> Union[int, NotImplementedType]: | ||
| return NotImplemented | ||
| def __sub__(self, other: object) -> Union[int, NotImplementedType]: | ||
| return 1 | ||
| def __isub__(self, other: object) -> int: | ||
| x: Union[int, NotImplementedType] | ||
| return x | ||
| def __mul__(self, other: object) -> Union[int, NotImplementedType]: | ||
| x: Union[int, NotImplementedType] | ||
| return x | ||
|
|
||
| [builtins fixtures/notimplemented.pyi] | ||
|
|
||
| [case testReturnNotImplementedABCSubclassHookMethod] | ||
| class A: | ||
| @classmethod | ||
| def __subclasshook__(cls, t: type[object], /) -> bool: | ||
| return NotImplemented | ||
| [builtins fixtures/notimplemented.pyi] | ||
|
|
||
| [case testReturnNotImplementedInNormalMethods] | ||
| from typing import Union | ||
| class A: | ||
| def f(self) -> bool: return NotImplemented # E: Incompatible return value type (got "_NotImplementedType", expected "bool") | ||
| def g(self) -> NotImplementedType: return True # E: Incompatible return value type (got "bool", expected "_NotImplementedType") | ||
| def h(self) -> NotImplementedType: return NotImplemented | ||
| def i(self) -> Union[bool, NotImplementedType]: return NotImplemented | ||
| def j(self) -> Union[bool, NotImplementedType]: return True | ||
| [builtins fixtures/notimplemented.pyi] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice duct tape application, but maybe we should consider changing that in typeshed (or our own typeshed patch) directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, my favourite would be to update typeshed. However, this was closed in typeshed/13488 due to something with
__eq__and the required adjustments for type checkers. I will ask around.I have not modified Mypy's own typeshed patch so far. I will try it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...it worked!