Will It Vibe logoWill It Vibe?
PY-004Medium severity-8 points

Mutable default argument

Part of Code Quality & Syntax, which counts for 20% of the overall score. When this check fires it deducts 8 points from that category, once per scan, no matter how many places it turns up.

What it detects

A default argument value of [], {}, list(), dict(), or set() is created once at function-definition time and shared across every call that relies on it.

Why it matters

A default argument value like [] or {} is created exactly once, when the function is defined, not on every call, so every call that relies on the default ends up sharing and mutating the same list or dict. This produces one of Python's most notorious bugs: a function that appears to work in isolation but accumulates stale data across unrelated calls, especially in a long-running process like a web server or worker. The bug is also nondeterministic in tests depending on call order, which makes it hard to reproduce.

How to fix it

Use None as the default and create the mutable value inside the function body, for example def add_tag(tag, tags=None): if tags is None: tags = []. The same applies to list(), dict(), and set() called directly as a default: they still only run once at definition time, so they carry the same risk as a literal [] or {}.

The paid report includes a ready-to-paste prompt for your AI coding agent for every check it finds, pointed at the exact findings from your scan. See pricing

Does your repo trip this check?

Paste a GitHub URL or drop a project folder. Scans run in your browser and take seconds.

Scan your repo

Related Code Quality & Syntax checks