[flake8-bugbear] Treat raise NotImplemented-only bodies as stub functions#10990
[flake8-bugbear] Treat raise NotImplemented-only bodies as stub functions#10990charliermarsh merged 9 commits intoastral-sh:mainfrom
flake8-bugbear] Treat raise NotImplemented-only bodies as stub functions#10990Conversation
|
040c1e2 to
fb5e255
Compare
| }) => exception.as_ref().is_some_and(|exc| { | ||
| semantic | ||
| .resolve_builtin_symbol(map_callable(exc)) | ||
| .is_some_and(|name| matches!(name, "NotImplementedError" | "NotImplemented")) |
There was a problem hiding this comment.
Changed this to use the semantic model, and allow raise NotImplementedError (without argument) and raise NotImplemented.
There was a problem hiding this comment.
Why do you allow raise NotImplemented? NotImplemented is not an exception. It should never be raised. NotImplemented can be returned by comparison operators.
There was a problem hiding this comment.
We have separate rules to guard against raise NotImplemented. But if the entire function is raise NotImplemented, it's almost certainly intended to be raise NotImplementedError, right?
fb5e255 to
5ba6a22
Compare
flake8-bugbear] Treat raise NotImplemented-only bodies as stub functions
|
|
||
|
|
||
| def quux(a: list = []): | ||
| raise NotImplemented |
There was a problem hiding this comment.
What's the purpose of this example?
There was a problem hiding this comment.
To verify that we treat raise NotImplemented like raise NotImplementedError. (Just to be clear, these aren't examples, they're tests.)
Summary
As discussed in #10083 (comment), stubs detection now also covers the case where the function body raises NotImplementedError and does nothing else.
Test Plan
Tests for the relevant cases were added in B006_8.py