mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:47 +00:00
[flake8-bugbear
] Ignore __debug__
attribute in B010
(#18357)
<!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? --> ## Summary Fixes #18353 <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan <!-- How was it tested? --> Snapshot tests
This commit is contained in:
parent
452f992fbc
commit
e23d4ea027
3 changed files with 13 additions and 0 deletions
|
@ -67,3 +67,6 @@ getattr(self.
|
||||||
|
|
||||||
import builtins
|
import builtins
|
||||||
builtins.getattr(foo, "bar")
|
builtins.getattr(foo, "bar")
|
||||||
|
|
||||||
|
# Regression test for: https://github.com/astral-sh/ruff/issues/18353
|
||||||
|
setattr(foo, "__debug__", 0)
|
||||||
|
|
|
@ -74,6 +74,11 @@ pub(crate) fn setattr_with_constant(checker: &Checker, expr: &Expr, func: &Expr,
|
||||||
if !is_identifier(name.to_str()) {
|
if !is_identifier(name.to_str()) {
|
||||||
return;
|
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()) {
|
if is_mangled_private(name.to_str()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -364,6 +364,8 @@ B009_B010.py:69:1: B009 [*] Do not call `getattr` with a constant attribute valu
|
||||||
68 | import builtins
|
68 | import builtins
|
||||||
69 | builtins.getattr(foo, "bar")
|
69 | builtins.getattr(foo, "bar")
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B009
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B009
|
||||||
|
70 |
|
||||||
|
71 | # Regression test for: https://github.com/astral-sh/ruff/issues/18353
|
||||||
|
|
|
|
||||||
= help: Replace `getattr` with attribute access
|
= help: Replace `getattr` with attribute access
|
||||||
|
|
||||||
|
@ -373,3 +375,6 @@ B009_B010.py:69:1: B009 [*] Do not call `getattr` with a constant attribute valu
|
||||||
68 68 | import builtins
|
68 68 | import builtins
|
||||||
69 |-builtins.getattr(foo, "bar")
|
69 |-builtins.getattr(foo, "bar")
|
||||||
69 |+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…
Add table
Add a link
Reference in a new issue