Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@

import builtins
builtins.getattr(foo, "bar")

# Regression test for: https://github.com/astral-sh/ruff/issues/18353
setattr(foo, "__debug__", 0)
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ pub(crate) fn setattr_with_constant(checker: &Checker, expr: &Expr, func: &Expr,
if !is_identifier(name.to_str()) {
return;
}
// Ignore if the attribute name is `__debug__`. Assigning to the `__debug__` property is a
// `SyntaxError`.
if name.to_str() == "__debug__" {
return;
}
if is_mangled_private(name.to_str()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ B009_B010.py:69:1: B009 [*] Do not call `getattr` with a constant attribute valu
68 | import builtins
69 | builtins.getattr(foo, "bar")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B009
70 |
71 | # Regression test for: https://github.com/astral-sh/ruff/issues/18353
|
= help: Replace `getattr` with attribute access

Expand All @@ -373,3 +375,6 @@ B009_B010.py:69:1: B009 [*] Do not call `getattr` with a constant attribute valu
68 68 | import builtins
69 |-builtins.getattr(foo, "bar")
69 |+foo.bar
70 70 |
71 71 | # Regression test for: https://github.com/astral-sh/ruff/issues/18353
72 72 | setattr(foo, "__debug__", 0)
Loading