Skip to content

A001 misses some attributes referenced within the class scope #20179

@dscorbett

Description

@dscorbett

Summary

builtin-variable-shadowing (A001) ignores some bindings in class scope which it checks in other scopes. Example:

$ cat >a001.py <<'# EOF'
class C:
    for id in [1]: pass
    def f1(self, x=id): return x

    (id := 2)
    def f2(self, x=id): return x

    from contextlib import nullcontext
    with nullcontext() as id: pass
    def f3(self, x=id): return x

c = C()
print(c.f1(), c.f2(), c.f3())
# EOF

$ python a001.py
1 2 None

$ ruff --isolated check a001.py --select A001
All checks passed!

$ flake8 --select A a001.py
a001.py:2:5: A001 variable "id" is shadowing a Python builtin
a001.py:5:6: A001 variable "id" is shadowing a Python builtin
a001.py:9:5: A001 variable "id" is shadowing a Python builtin

It might make more sense to report these for builtin-attribute-shadowing (A003), but A001 is how the upstream plugin categorizes them. Either way, they are false negatives.

Version

ruff 0.12.11 (c2bc15b 2025-08-28)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions