builtins: NotImplemented is not callable#4222
Merged
JelleZijlstra merged 1 commit intopython:masterfrom Jun 11, 2020
Merged
Conversation
JelleZijlstra
approved these changes
Jun 11, 2020
Member
JelleZijlstra
left a comment
There was a problem hiding this comment.
If mypy is fine with this, I'm fine with it too.
vishalkuo
pushed a commit
to vishalkuo/typeshed
that referenced
this pull request
Jun 26, 2020
Fixes python#3315 Co-authored-by: hauntsaninja <>
JukkaL
pushed a commit
to python/mypy
that referenced
this pull request
Oct 9, 2024
Refs #5710 Adds special-case handling for raising `NotImplemented`: ```python raise NotImplemented # E: Exception must be derived from BaseException; did you mean "NotImplementedError"? ``` Per the linked issue, there's some debate as to how to best handle `NotImplemented`. This PR special-cases its behavior in `raise` statements, whereas the leaning in the issue (at the time it was opened) was towards updating its definition in typeshed and possibly special-casing its use in the relevant dunder methods. Going the typeshed/special-dunder route may still happen, but it hasn't in the six years since the issue was opened. It would be nice to at least catch errors from raising `NotImplemented` in the interim. Making this change also uncovered a regression introduced in python/typeshed#4222. Previously, `NotImplemented` was annotated as `Any` in typeshed, so returning `NotImplemented` from a non-dunder would emit an error when `--warn-return-any` was used: ```python class A: def some(self) -> bool: return NotImplemented # E: Returning Any from function declared to return "bool" ``` However, in python/typeshed#4222, the type of `NotImplemented` was updated to be a subclass of `Any`. This broke the handling of `--warn-return-any`, but it wasn't caught since the definition of `NotImplemented` in `fixtures/notimplemented.pyi` wasn't updated along with the definition in typeshed. As a result, current mypy doesn't emit an error here ([playground](https://mypy-play.net/?mypy=1.11.2&python=3.12&flags=strict%2Cwarn-return-any&gist=8a78e3eb68b0b738f73fdd326f0bfca1)), despite having a test case saying that it should. As a bandaid, this PR add special handling for `NotImplemented` in return statements to treat it like an explicit `Any`, restoring the pre- python/typeshed#4222 behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3315