Skip to content
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
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ limitations make it difficult.
**B028**: No explicit stacklevel argument found. The warn method from the warnings module uses a
stacklevel of 1 by default. This will only show a stack trace for the line on which the warn method is called.
It is therefore recommended to use a stacklevel of 2 or greater to provide more information to the user.
The check is skipped when skip_file_prefixes is used.

.. _B029:

Expand Down
1 change: 1 addition & 0 deletions bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,7 @@ def check_for_b028(self, node) -> None:
and isinstance(node.func.value, ast.Name)
and node.func.value.id == "warnings"
and not any(kw.arg == "stacklevel" for kw in node.keywords)
and not any(kw.arg == "skip_file_prefixes" 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)
Expand Down
1 change: 1 addition & 0 deletions tests/b028.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
kwargs = {"message": "test", "category": DeprecationWarning, "stacklevel": 1}
warnings.warn(**kwargs)
warnings.warn(*args, **kwargs)
warnings.warn("test", DeprecationWarning, skip_file_prefixes=["foo"])
Loading