Repolode
PyCQA

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. 1

    Install the plugin from PyPI with pip

    pip install flake8-bugbear
  2. 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