-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[flake8-bugbear
] Treat raise NotImplemented
-only bodies as stub functions
#10990
Conversation
|
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.
Thanks!
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed this to use the semantic model, and allow raise NotImplementedError
(without argument) and raise NotImplemented
.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
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.
I see, fair enough!
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this example?
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.
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