# flake8-bugbear

> A plugin for flake8 finding likely bugs and design problems in your program. Contains warnings that don't belong in pyflakes and pycodestyle.

- **URL**: https://www.freshcrate.ai/projects/flake8-bugbear
- **Author**: pypi
- **Category**: Frameworks
- **Latest version**: `main@2026-05-29` (2026-05-29)
- **License**: MIT
- **Source**: https://github.com/PyCQA/flake8-bugbear#change-log
- **Homepage**: https://pypi.org/project/flake8-bugbear/
- **Language**: Python
- **GitHub**: 1,115 stars, 115 forks
- **Registry**: pypi (`flake8-bugbear`)
- **Tags**: `bugbear`, `bugs`, `flake8`, `linter`, `pyflakes`, `pylint`, `pypi`, `qa`

## Description

==============
flake8-bugbear
==============

.. image:: https://github.com/PyCQA/flake8-bugbear/actions/workflows/ci.yml/badge.svg
   :target: https://github.com/PyCQA/flake8-bugbear/actions/workflows/ci.yml

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black

.. image:: https://results.pre-commit.ci/badge/github/PyCQA/flake8-bugbear/main.svg
   :target: https://results.pre-commit.ci/latest/github/PyCQA/flake8-bugbear/main
   :alt: pre-commit.ci status

A plugin for ``flake8`` finding likely bugs and design problems in your
program.  Contains warnings that don't belong in ``pyflakes`` and
``pycodestyle``::

    bug·bear  (bŭg′bâr′)
    n.
    1. A cause of fear, anxiety, or irritation: *Overcrowding is often
       a bugbear for train commuters.*
    2. A difficult or persistent problem: *"One of the major bugbears of
       traditional AI is the difficulty of programming computers to
       recognize that different but similar objects are instances of the
       same type of thing" (Jack Copeland).*
    3. A fearsome imaginary creature, especially one evoked to frighten
       children.

It is felt that these lints don't belong in the main Python tools as they
are very opinionated and do not have a PEP or standard behind them. Due to
``flake8`` being designed to be extensible, the original creators of these lints
believed that a plugin was the best route. This has resulted in better development
velocity for contributors and adaptive deployment for ``flake8`` users.

Installation
------------

Install from ``pip`` with:

.. code-block:: sh

     pip install flake8-bugbear

It will then automatically be run as part of ``flake8``; you can check it has
been picked up with:

.. code-block:: sh

    $ flake8 --version
    3.5.0 (assertive: 1.0.1, flake8-bugbear: 18.2.0, flake8-comprehensions: 1.4.1, mccabe: 0.6.1, pycodestyle: 2.3.1, pyflakes: 1.6.0) CPython 3.7.0 on Darwin

Development
-----------

If you'd like to do a PR we have development instructions `here <https://github.com/PyCQA/flake8-bugbear/blob/master/DEVELOPMENT.md>`_.

List of warnings
----------------

.. _B001:

**B001**: Do not use bare ``except:``, it also catches unexpected events
like memory errors, interrupts, system exit, and so on.  Prefer ``except
Exception:``.  If you're sure what you're doing, be explicit and write
``except BaseException:``.  Disable ``E722`` to avoid duplicate warnings.

.. _B002:

**B002**: Python does not support the unary prefix increment. Writing
``++n`` is equivalent to ``+(+(n))``, which equals ``n``. You meant ``n
+= 1``.

.. _B003:

**B003**: Assigning to ``os.environ`` doesn't clear the
environment.  Subprocesses are going to see outdated
variables, in disagreement with the current process.  Use
``os.environ.clear()`` or the ``env=``  argument to Popen.

.. _B004:

**B004**: Using ``hasattr(x, '__call__')`` to test if ``x`` is callable
is unreliable.  If ``x`` implements custom ``__getattr__`` or its
``__call__`` is itself not callable, you might get misleading
results.  Use ``callable(x)`` for consistent results.

.. _B005:

**B005**: Using ``.strip()`` with multi-character strings is misleading
the reader. It looks like stripping a substring. Move your
character set to a constant if this is deliberate. Use
``.replace()``, ``.removeprefix()``, ``.removesuffix()`` or regular
expressions to remove string fragments.

.. _B006:

**B006**: Do not use mutable data structures for argument defaults.  They
are created during function definition time. All calls to the function
reuse this one instance of that data structure, persisting changes
between them.

.. _B007:

**B007**: Loop control variable not used within the loop body.  If this is
intended, start the name with an underscore.

.. _B008:

**B008**: Do not perform function calls in argument defaults.  The call is
performed only once at function definition time. All calls to your
function will reuse the result of that definition-time function call.  If
this is intended, assign the function call to a module-level variable and
use that variable as a default value.

.. _B009:

**B009**: Do not call ``getattr(x, 'attr')``, instead use normal
property access: ``x.attr``. Missing a default to ``getattr`` will cause
an ``AttributeError`` to be raised for non-existent properties. There is
no additional safety in using ``getattr`` if you know the attribute name
ahead of time.

.. _B010:

**B010**: Do not call ``setattr(x, 'attr', val)``, instead use normal
property access: ``x.attr = val``. There is no additional safety in
using ``setattr`` if you know the attribute name ahead of time.

.. _B011:

**B011**: Do not call ``assert False`` since ``python -O`` removes these calls.
Instead callers should ``raise AssertionError()``.

.. _B012:

**B012**: Use of ``break``, ``continue`` or ``return`` inside ``finally`` blocks will
silence exceptions or override return values from the ``try`` or ``except`` blocks.
To s

## Recent releases

| Version | Date | Urgency | Changes |
| --- | --- | --- | --- |
| `main@2026-05-29` | 2026-05-29 | High | Latest activity on main branch |
| `25.11.29` | 2026-04-21 | Low | Imported from PyPI (25.11.29) |
| `main@2026-03-16` | 2026-03-16 | Low | Latest activity on main branch |
| `main@2026-03-16` | 2026-03-16 | Low | Latest activity on main branch |
| `main@2026-03-16` | 2026-03-16 | Low | Latest activity on main branch |
| `25.10.21` | 2025-10-22 | Low | * B042: New check for reminding to call super().__init__ in custom exceptions * B028: Skip if skip_file_prefixes is used (#503) * B912: New check for `map()` without an explicit `strict=` parameter. (#516) * Add python3.14 Support / CI * Remove python3.9 support / CI * flake8-bugbear now requires at least Python 3.10, like the next release of flake8 |
| `24.12.12` | 2024-12-12 | Low | * B012 and B025 now also handle try/except* (#500) * Skip B028 if warnings.warn is called with ``*args`` or ``**kwargs`` (#501) * Add B911: itertools.batched without strict= (#502) * Readme has anchors per check (they do not seem to render on GitHub tho) |
| `24.10.31` | 2024-10-31 | Low | * B041: New dictionary same key AND value check (#496) * B037: Fix typo in error message * B024: No longer treats assigned class variables as abstract (#471) * Bump required attrs version to 22.2.0 |
| `24.8.19` | 2024-08-20 | Low | * B910: implement to suggest using Counter() instead of defaultdict(int) (#489) * B901: Do not trigger with explicit Generator return type (#481) * B008: add some comments, rename b008_extend_immutable_calls (#476) * B040: exception with note added not reraised or used (#477) * B039, Add ``ContextVar`` with mutable literal or function call as default * B040: Add Exception with added note not reraised. (#474) * Run tests in Python 3.13 * Type annotated code (#481 + #483) * Replace hash wi |
| `24.4.26` | 2024-04-26 | Low | * B909: Fix false positive affecting containers of mutables (#469) |

## Citation

- HTML: https://www.freshcrate.ai/projects/flake8-bugbear
- Markdown: https://www.freshcrate.ai/projects/flake8-bugbear.md
- Dependencies JSON: https://www.freshcrate.ai/api/projects/flake8-bugbear/deps

_Generated by freshcrate.ai. Indexes pypi releases for AI-agent ecosystem packages._
