set-attr-with-constant
What it does
Section titled “What it does”Reports a statement setattr(x, "name", v) with a literal name that is a valid identifier.
Why it matters
Section titled “Why it matters”setattr is for names known only at run time. With a fixed name x.name = v does the same and is checked by type checkers and found by searches for the attribute.
To fix, write x.name = v.
Example
Section titled “Example”...getattr(x, "__private")getattr(x, "class")getattr(x, "name", None)setattr(x, "name", 1)y = setattr(x, "name", 1)setattr(x, "class", 1)...Configuration
Section titled “Configuration”python: lint: rules: set-attr-with-constant: warn # off (default), warn, errorEnabled by the presets: python/ruff.
Suppress one line with sudsy-disable-next-line set-attr-with-constant 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 | B010 |
full |