Skip to content

Commit 4fed293

Browse files
harupycooperlees
andauthored
Skip B028 if warnings.warn is called with *args or **kwargs (#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]>
1 parent 994f3dd commit 4fed293

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

bugbear.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,8 @@ def check_for_b028(self, node) -> None:
16831683
and node.func.value.id == "warnings"
16841684
and not any(kw.arg == "stacklevel" for kw in node.keywords)
16851685
and len(node.args) < 3
1686+
and not any(isinstance(a, ast.Starred) for a in node.args)
1687+
and not any(kw.arg is None for kw in node.keywords)
16861688
):
16871689
self.errors.append(B028(node.lineno, node.col_offset))
16881690

tests/b028.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@
1111
warnings.warn("test", DeprecationWarning, stacklevel=1)
1212
warnings.warn("test", DeprecationWarning, 1)
1313
warnings.warn("test", category=DeprecationWarning, stacklevel=1)
14+
args = ("test", DeprecationWarning, 1)
15+
warnings.warn(*args)
16+
kwargs = {"message": "test", "category": DeprecationWarning, "stacklevel": 1}
17+
warnings.warn(**kwargs)
18+
warnings.warn(*args, **kwargs)

0 commit comments

Comments
 (0)