Skip to content

Commit

Permalink
Skip B028 if warnings.warn is called with *args or **kwargs (#…
Browse files Browse the repository at this point in the history
…501)

* Avoid raising B028 if warnings.warn contains *args or **kwargs

* Update tests/b028.py

Co-authored-by: Cooper Lees <[email protected]>

---------

Co-authored-by: Cooper Lees <[email protected]>
  • Loading branch information
harupy and cooperlees authored Dec 9, 2024
1 parent 994f3dd commit 4fed293
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,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)
warnings.warn(*args, **kwargs)

0 comments on commit 4fed293

Please sign in to comment.