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