skillfed

flake8-mutable

mutable defaults flake8 extension

flake8-mutable v1.2.0 166.2K downloads/30d#10,506 on PyPI44
Permissive license MIT Active released

What it is and what it does

flake8-mutable is a linter plugin for flake8 that catches a subtle but common Python gotcha: mutable default arguments. When you define a function with a mutable default like `def func(arg=[])`, that same list object is reused across all calls, so mutations in one call affect subsequent calls. This plugin scans your code and flags these patterns with error codes like M511 for dict defaults.

It integrates directly into flake8's checking pipeline, so once installed, it runs automatically when you invoke flake8 on your codebase. The plugin has no runtime dependencies beyond flake8 itself, making it a lightweight addition to your linting setup. It's designed for developers who want to catch this class of bug early during code review or CI/CD checks.

Use it for:

  • Add to your flake8 configuration in CI/CD to catch mutable defaults before code review.
  • Use during local development to flag function definitions with mutable defaults as you write.
  • Audit an existing codebase for instances of this anti-pattern across many files at once.
  • Enforce a team coding standard that prohibits mutable defaults in function signatures.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

A flake8 plugin that detects mutable default arguments in Python function definitions, flagging a common source of unexpected behavior where mutations persist across function calls.

Yes, if you use flake8 and want to catch mutable default arguments automatically. The plugin is lightweight, has no dependencies, and addresses a real Python pitfall. The long gap since the last release (2017) is a minor concern, but the repository remains active and the plugin's scope is narrow enough that it is unlikely to break with new Python versions.

Install

flake8-mutable on PyPI

pip

pip install flake8-mutable

uv

uv add flake8-mutable

poetry

poetry add flake8-mutable

Installing flake8-mutable

Before you install

Low friction install with no runtime dependencies. Last release was in 2017 but the repository remains active with a recent commit in 2026, suggesting ongoing maintenance despite infrequent version updates.

License in practice

MIT license is permissive and poses no restrictions on commercial or private use.

Quickstart

pip install flake8-mutable

Then run flake8 on your code:
flake8 your_file.py

flake8 will report violations like:
foo.py:2:14: M511 - mutable default arg of type Dict

Requires flake8 to be installed and available in your environment; the plugin integrates as a flake8 extension.

Verify before relying

  • Whether the package actively detects all mutable types (lists, dicts, sets) or if coverage has gaps.
  • Current compatibility with recent flake8 versions and Python 3.7+, given the latest release was in 2017.

Package facts

License MIT (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance actively maintained — 3,399 days since the last release
Last repo commit
First released
Downloads 166,166/month — #10,506 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: flake8_mutable-1.2.0-py2-none-any.whl

Keywords: flake8, mutable, arg, kwarg

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 2Programming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Topic :: Software Development :: Libraries :: Python Modules

Tags

flake8 mutable defaultsdetect mutable argumentspython function default argsflake8 code qualitymutable default checker
lintingcode-qualityflake8-plugin

More Python Modules packages