{"id":2026,"library":"flake8-bugbear","title":"flake8-bugbear","description":"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.","status":"active","version":"25.11.29","language":"en","source_language":"en","source_url":"https://github.com/PyCQA/flake8-bugbear","tags":["flake8","linter","static analysis","code quality","bug detection","python3"],"install":[{"cmd":"pip install flake8-bugbear","lang":"bash","label":"Install flake8-bugbear"}],"dependencies":[{"reason":"flake8-bugbear is a plugin for flake8 and requires flake8 to function.","package":"flake8","optional":false},{"reason":"A core dependency required by the library.","package":"attrs","optional":false}],"imports":[{"note":"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`).","symbol":"N/A","correct":"N/A"}],"quickstart":{"code":"# bad_code.py\ndef mutable_default(a, b=[]):\n    b.append(a)\n    return b\n\nresult1 = mutable_default(1)\nresult2 = mutable_default(2) # This will trigger B006\n\ndef bare_except_example():\n    try:\n        1/0\n    except: # This will trigger B001\n        pass\n\nclass MyCustomException(Exception):\n    def __init__(self, message):\n        self.message = message\n        # B042 will warn about missing super().__init__\n\ndelattr(object(), 'attribute') # B043 will warn about delattr with constant\n\n# Run from your terminal after saving as bad_code.py:\n# pip install flake8 flake8-bugbear\n# flake8 bad_code.py","lang":"python","description":"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)."},"warnings":[{"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`).","message":"Starting with version 25.10.21, flake8-bugbear dropped support for Python 3.9. It now requires Python 3.10 or newer.","severity":"breaking","affected_versions":">=25.10.21"},{"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.","message":"If 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.","severity":"breaking","affected_versions":"flake8>=5.0"},{"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.","message":"Bugbear'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.","severity":"deprecated","affected_versions":"All versions"},{"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 []`.","message":"Using 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.","severity":"gotcha","affected_versions":"All versions (B006 check)"},{"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.","message":"Bare `except:` statements (B001) catch all exceptions, including `SystemExit`, `KeyboardInterrupt`, and `MemoryError`, which can hide critical issues or prevent graceful shutdowns.","severity":"gotcha","affected_versions":"All versions (B001 check)"},{"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.","message":"flake8-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.","severity":"gotcha","affected_versions":"All versions (new checks are added in minor/patch releases)"},{"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`).","message":"The B9xx series of checks are considered 'opinionated' and are often not enabled by default. They require explicit selection in your `flake8` configuration.","severity":"gotcha","affected_versions":"All versions (B9xx checks)"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}