Skip to content

B028: flag empty skip_file_prefixes tuples - #575

Merged
cooperlees merged 1 commit into
PyCQA:mainfrom
Sonike:fix/b028-empty-skip-file-prefixes
Sep 7, 2026
Merged

B028: flag empty skip_file_prefixes tuples#575
cooperlees merged 1 commit into
PyCQA:mainfrom
Sonike:fix/b028-empty-skip-file-prefixes

Conversation

@Sonike

@Sonike Sonike commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #510

Summary

  • report B028 when warnings.warn receives an explicitly empty skip_file_prefixes=() tuple
  • continue skipping calls whose prefixes are non-empty or cannot be determined statically
  • document the exception and add regression coverage

An empty tuple does not cause warnings.warn to raise the effective stack level, so treating it like a populated skip_file_prefixes value suppresses a useful B028 diagnostic.

Tests

  • .venv/bin/python -m pytest tests/test_bugbear.py -q (81 passed)
  • .venv/bin/tox -e py314 (81 passed, 98% coverage)
  • .venv/bin/pre-commit run --all-files (isort, black, flake8, rstcheck passed)

Limitations

Dynamic expressions remain intentionally conservative: if the value of skip_file_prefixes is not a literal empty tuple, B028 is skipped as before.

An explicitly empty tuple does not raise warnings.warn's effective stacklevel, so B028 should still report it. Keep skipping dynamic and non-empty values, and cover both paths in the eval fixture.
@cooperlees

Copy link
Copy Markdown
Collaborator

This is an improvement. Thanks!

@cooperlees
cooperlees merged commit b47cb86 into PyCQA:main Sep 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check for empty skip_file_prefixes in B028

2 participants