flake8-bugbear

25.11.29 · active · verified Thu Apr 09

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.

Warnings

Install

Imports

Quickstart

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

view raw JSON →