Skip to content
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

Skip B028 if warnings.warn is called with *args or **kwargs #501

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,8 @@ def check_for_b028(self, node) -> None:
and node.func.value.id == "warnings"
and not any(kw.arg == "stacklevel" for kw in node.keywords)
and len(node.args) < 3
and not any(isinstance(a, ast.Starred) for a in node.args)
and not any(kw.arg is None for kw in node.keywords)
):
self.errors.append(B028(node.lineno, node.col_offset))

Expand Down
5 changes: 5 additions & 0 deletions tests/b028.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@
warnings.warn("test", DeprecationWarning, stacklevel=1)
warnings.warn("test", DeprecationWarning, 1)
warnings.warn("test", category=DeprecationWarning, stacklevel=1)
args = ("test", DeprecationWarning, 1)
warnings.warn(*args)
kwargs = {"message": "test", "category": DeprecationWarning, "stacklevel": 1}
warnings.warn(**kwargs)
harupy marked this conversation as resolved.
Show resolved Hide resolved
warnings.warn(*args, **kwargs)
Loading