A flake8 and Pylama plugin that checks whether Python imports are grouped and ordered according to a chosen style guide.
PyCQA/flake8-bugbear
A Flake8 plugin that flags likely bugs and questionable design patterns that pyflakes and pycodestyle don't check.
- Stars
- 1,124
- Forks
- 134
- Open issues
- 40
- Last commit
- 11 hours ago
What is it?
flake8-bugbear is a plugin for Flake8, the Python linter, that adds checks for likely bugs and design problems. Its warnings cover patterns such as bare except clauses, mutable argument defaults, function calls in argument defaults, loop variables that override the iterable being looped over, and late-binding closures inside loops.
The checks are opinionated and sit outside the standard pyflakes and pycodestyle rules, so the plugin keeps them separate. Each warning has a B-prefixed code, and a set of opinionated B9xx checks is disabled by default and must be enabled explicitly through extend-select. Behavior can be tuned with settings such as extend-immutable-calls and classmethod-decorators.
Installation is a single pip install, after which Flake8 picks the plugin up automatically.
Key features
- 01Detects bare except clauses and suggests catching more specific exceptions.
- 02Flags mutable argument defaults and function calls in default values.
- 03Warns about loop variables that are unused or that shadow the iterable being iterated.
- 04Catches common mistakes such as assert False, useless expressions and getattr with a constant attribute name.
- 05Offers opinionated B9xx checks that are disabled by default and enabled through configuration.
Use cases
- Adding bug-focused linting to a Python project that already runs Flake8 in CI.
- Catching mutable default arguments and late-binding closure mistakes during code review.
- Enforcing stricter exception handling rules across a team codebase.
Quick start
- 1
Install the plugin from PyPI with pip
pip install flake8-bugbear - 2
Check that flake8 has picked up the plugin
flake8 --version
Things to know
- It only works as a plugin for flake8, so you need flake8 installed.
- Several of its checks are opinionated and have no PEP or standard behind them.
In collections
Topics
FAQ
- What is flake8-bugbear?
- A Flake8 plugin that flags likely bugs and questionable design patterns that pyflakes and pycodestyle don't check. flake8-bugbear is a plugin for Flake8, the Python linter, that adds checks for likely bugs and design problems. Its warnings cover patterns such as bare except clauses, mutable argument defaults, function calls in argument defaults, loop variables that override the iterable being looped over, and late-binding closures inside loops.
- Is flake8-bugbear free to use? What license does it have?
- flake8-bugbear is open source under the MIT license. Check the license terms before using it in commercial products.
- Is flake8-bugbear still maintained?
- Actively maintained. The last commit to flake8-bugbear was on Nov 6, 2026.
- What can I use flake8-bugbear for?
- Adding bug-focused linting to a Python project that already runs Flake8 in CI. Catching mutable default arguments and late-binding closure mistakes during code review. Enforcing stricter exception handling rules across a team codebase.
- How do I install flake8-bugbear?
- Install the plugin from PyPI with pip: pip install flake8-bugbear Check that flake8 has picked up the plugin: flake8 --version
- Where can I get flake8-bugbear?
- The source code and installation instructions are on GitHub: https://github.com/PyCQA/flake8-bugbear
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A single-file Python checker that tests code against the style conventions of PEP 8, using only the standard library.
A Python linter that wraps PyFlakes, pycodestyle and McCabe into one command, with support for third-party plugins.
A strict, opinionated flake8 plugin that enforces consistent, simple Python code style and flags complex code patterns.
A Python tool that computes McCabe cyclomatic complexity for functions and runs as a flake8 plugin to flag overly complex code.
A flake8 plugin that flags insecure and bad Python coding patterns, such as use of exec or unsafe deserialization.