Registry / testing / flake8-bugbear

flake8-bugbear

JSON →
library25.11.29pypypi✓ verified 31d ago

A plugin for flake8 finding likely bugs and design problems in your program. It contains warnings that don't belong in pyflakes and pycodestyle, offering more opinionated checks. The current version is 25.11.29, with releases occurring several times a year, often adding new checks or refining existing ones.

pip install flake8-bugbear
INSTALL
IMPORT
SIG · FLAKE8-BUGBEAR
F
flake8-bugbear
testingpythonv25.11.29
Install
1.9s avg
Import
—
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v25.11.29 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 20MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.9s · import 0.000s · 21MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

N/A
✓ N/A
flake8-bugbear is a plugin that is automatically loaded by flake8 upon installation. There are no direct Python imports for end-user application code. Configuration is done via `flake8`'s configuration files (e.g., `.flake8`, `setup.cfg`, `pyproject.toml`).

Install `flake8` and `flake8-bugbear`, then run `flake8` on a Python file. `flake8-bugbear`'s checks will be automatically included in the output, demonstrating common warnings like mutable default arguments (B006), bare excepts (B001), and issues with custom exception `__init__` (B042).

# bad_code.py def mutable_default(a, b=[]): b.append(a) return b result1 = mutable_default(1) result2 = mutable_default(2) # This will trigger B006 def bare_except_example(): try: 1/0 except: # This will trigger B001 pass class MyCustomException(Exception): def __init__(self, message): self.message = message # B042 will warn about missing super().__init__ delattr(object(), 'attribute') # B043 will warn about delattr with constant # Run from your terminal after saving as bad_code.py: # pip install flake8 flake8-bugbear # flake8 bad_code.py
flake8 --version
Debug
Known issues
breakingStarting with version 25.10.21, flake8-bugbear dropped support for Python 3.9. It now requires Python 3.10 or newer.
fix
Upgrade your Python environment to 3.10 or a later version. If unable to upgrade Python, pin flake8-bugbear to a version less than 25.10.21 (e.g., `flake8-bugbear<25.10.21`).
affects: >=25.10.21
breakingIf you are using flake8 version 5.0 or newer, checks for plugins (including flake8-bugbear) are no longer enabled by default unless explicitly selected. This can lead to flake8-bugbear checks not running.
fix
Explicitly enable the B-series checks in your flake8 configuration (e.g., in `.flake8`, `setup.cfg`, or `pyproject.toml`) by adding `select = C,E,F,W,B` or by using the `--extend-select=B` command-line option.
affects: flake8>=5.0
deprecatedBugbear's internal enforcement for explicit selection of its 'opinionated warnings' (B9xx checks) is deprecated and will be removed in a future release. While currently requiring explicit selection, the mechanism for doing so will change.
fix
It is recommended to use `extend-ignore` and `extend-select` in your flake8 configuration to manage which codes are active, aligning with future flake8 plugin best practices.
affects: All versions
gotchaUsing mutable objects (like lists or dictionaries) as default arguments in function definitions can lead to unexpected behavior, as the default object is shared across all calls.
fix
Initialize mutable defaults inside the function, typically by setting the default to `None` and then checking for `None` to create a new mutable object. Example: `def func(arg=None): arg = arg or []`.
affects: All versions (B006 check)
gotchaBare `except:` statements (B001) catch all exceptions, including `SystemExit`, `KeyboardInterrupt`, and `MemoryError`, which can hide critical issues or prevent graceful shutdowns.
fix
Always specify the exception type to catch, usually `except Exception:`, or `except SomeSpecificError:` for more targeted handling. Use `except BaseException:` only when truly intending to catch all possible exceptions.
affects: All versions (B001 check)
gotchaflake8-bugbear regularly introduces new checks (e.g., B042 for missing `super().__init__` in custom exceptions, B043 for `delattr` with constant, B912 for `map()` without `strict=`). Upgrading the library may introduce new warnings in existing code.
fix
Review the release notes for new versions to understand new checks and their implications. Configure your `.flake8` or `pyproject.toml` to ignore specific new checks if they are not relevant to your project or if you need to address them incrementally.
affects: All versions (new checks are added in minor/patch releases)
gotchaThe B9xx series of checks are considered 'opinionated' and are often not enabled by default. They require explicit selection in your `flake8` configuration.
fix
Add `B9` to your `select` option in your `flake8` configuration (e.g., `select = C,E,F,W,B,B9`) to enable all opinionated checks, or select specific ones (e.g., `select = B901,B950`). Some B9xx checks might require ignoring other flake8 checks (e.g., `E501` for `B950`).
affects: All versions (B9xx checks)
Upgrade
Version history
25.11.29latest on PyPI · released Nov 29, 2025
Audit
Dependencies
flake8requiredflake8-bugbear is a plugin for flake8 and requires flake8 to function.
attrsrequiredA core dependency required by the library.
Agent activity
9 hits · last 30 days
node
8
Resources
flake8-bugbear — pip install flake8-bugbear · libregistry