Skip to content

B010 should ignore the attribute __debug__ #18353

@dscorbett

Description

@dscorbett

Summary

set-attr-with-constant (B010) should not apply when the attribute name is "__debug__".

$ cat >b010.py <<'# EOF'
x = type("C", (), {})
setattr(x, "__debug__", 0)
print(x.__debug__)
# EOF

$ python b010.py
0

$ ruff --isolated check b010.py --select B010 --fix
Found 1 error (1 fixed, 0 remaining).

$ python b010.py
  File "b010.py", line 2
    x.__debug__ = 0
    ^^^^^^^^^^^
SyntaxError: cannot assign to __debug__

Version

ruff 0.11.11 (0397682 2025-05-22)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions