-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[flake8-bugbear] Ignore B028 if skip_file_prefixes is present
#18047
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
Changes from 2 commits
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 |
|---|---|---|
|
|
@@ -60,10 +60,16 @@ pub(crate) fn no_explicit_stacklevel(checker: &Checker, call: &ast::ExprCall) { | |
| return; | ||
| } | ||
|
|
||
| // Signature as of Python 3.13 (https://docs.python.org/3/library/warnings.html#warnings.warn) | ||
| // ```text | ||
| // 0 1 2 3 4 | ||
| // warnings.warn(message, category=None, stacklevel=1, source=None, *, skip_file_prefixes=()) | ||
| // ``` | ||
| if call | ||
| .arguments | ||
| .find_argument_value("stacklevel", 2) | ||
| .is_some() | ||
| || call.arguments.find_keyword("skip_file_prefixes").is_some() | ||
|
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 think you have to check that the value is a nonempty tuple of strings. Could you also add a test for if a user directly specifies
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. (If the expression is not a literal tuple of strings, then I think it's okay to skip the lint, even though that might be a false negative).
Contributor
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. I think we need to check if the tuple is nonempty, because if we check for a tuple of strings, this case
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. Sorry maybe I worded that in a confusing way:
The logic you have in the most recent commit will give a false positive in the case where the user does something like this: _my_prefixes = ("this","that")
warnings.warn("test", skip_file_prefixes = _my_prefixes)Could you add this as another test case and take another stab at the implementation logic?
Contributor
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. I've updated the implementation logic |
||
| || call | ||
| .arguments | ||
| .args | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.