mutable-class-default
What it does
Section titled “What it does”Reports a class attribute assigned a list, dict, set or comprehension, or a call that builds one, with no ClassVar or Final annotation. Data classes, Pydantic models and named tuples are left alone.
Why it matters
Section titled “Why it matters”A class attribute belongs to the class and is shared by every instance. self.items.append(x) on one instance changes all of them, which is rarely meant.
To fix, create the value in __init__, or annotate the attribute ClassVar if sharing is the intent.
Example
Section titled “Example”... return a
class A: x = []
...
...Configuration
Section titled “Configuration”python: lint: rules: mutable-class-default: warn # off (default), warn, errorEnabled by the presets: python/ruff.
Suppress one line with sudsy-disable-next-line mutable-class-default in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| ruff | RUF012 |
full |