diff --git a/README.rst b/README.rst index fb2eae4..db5af4a 100644 --- a/README.rst +++ b/README.rst @@ -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: diff --git a/bugbear.py b/bugbear.py index 09fab9f..96720b6 100644 --- a/bugbear.py +++ b/bugbear.py @@ -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) diff --git a/tests/b028.py b/tests/b028.py index 62e761b..1490e99 100644 --- a/tests/b028.py +++ b/tests/b028.py @@ -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"])