---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access.
  --> B009_B010.py:50:1
   |
49 | # Invalid usage
50 | setattr(foo, "bar", None)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^
51 | setattr(foo, "_123abc", None)
52 | setattr(foo, "__123abc__", None)
   |
help: Replace `setattr` with assignment
   |
49 | # Invalid usage
   - setattr(foo, "bar", None)
50 + foo.bar = None
51 | setattr(foo, "_123abc", None)
   |

B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access.
  --> B009_B010.py:51:1
   |
49 | # Invalid usage
50 | setattr(foo, "bar", None)
51 | setattr(foo, "_123abc", None)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
52 | setattr(foo, "__123abc__", None)
53 | setattr(foo, "abc123", None)
   |
help: Replace `setattr` with assignment
   |
50 | setattr(foo, "bar", None)
   - setattr(foo, "_123abc", None)
51 + foo._123abc = None
52 | setattr(foo, "__123abc__", None)
   |

B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access.
  --> B009_B010.py:52:1
   |
50 | setattr(foo, "bar", None)
51 | setattr(foo, "_123abc", None)
52 | setattr(foo, "__123abc__", None)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53 | setattr(foo, "abc123", None)
54 | setattr(foo, r"abc123", None)
   |
help: Replace `setattr` with assignment
   |
51 | setattr(foo, "_123abc", None)
   - setattr(foo, "__123abc__", None)
52 + foo.__123abc__ = None
53 | setattr(foo, "abc123", None)
   |

B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access.
  --> B009_B010.py:53:1
   |
51 | setattr(foo, "_123abc", None)
52 | setattr(foo, "__123abc__", None)
53 | setattr(foo, "abc123", None)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54 | setattr(foo, r"abc123", None)
55 | setattr(foo.bar, r"baz", None)
   |
help: Replace `setattr` with assignment
   |
52 | setattr(foo, "__123abc__", None)
   - setattr(foo, "abc123", None)
53 + foo.abc123 = None
54 | setattr(foo, r"abc123", None)
   |

B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access.
  --> B009_B010.py:54:1
   |
52 | setattr(foo, "__123abc__", None)
53 | setattr(foo, "abc123", None)
54 | setattr(foo, r"abc123", None)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55 | setattr(foo.bar, r"baz", None)
   |
help: Replace `setattr` with assignment
   |
53 | setattr(foo, "abc123", None)
   - setattr(foo, r"abc123", None)
54 + foo.abc123 = None
55 | setattr(foo.bar, r"baz", None)
   |

B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access.
  --> B009_B010.py:55:1
   |
53 | setattr(foo, "abc123", None)
54 | setattr(foo, r"abc123", None)
55 | setattr(foo.bar, r"baz", None)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56 |
57 | # Regression test for: https://github.com/astral-sh/ruff/issues/7455#issuecomment-1722458885
   |
help: Replace `setattr` with assignment
   |
54 | setattr(foo, r"abc123", None)
   - setattr(foo.bar, r"baz", None)
55 + foo.bar.baz = None
56 |
   |

B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access.
  --> B009_B010.py:81:1
   |
79 | # Example: the long s character "ſ" normalizes to "s" under NFKC.
80 | getattr(foo, "ſ")
81 | setattr(foo, "ſ", 1)
   | ^^^^^^^^^^^^^^^^^^^^
   |
help: Replace `setattr` with assignment
   |
80 | getattr(foo, "ſ")
   - setattr(foo, "ſ", 1)
81 + foo.ſ = 1
82 |
   |
note: This is an unsafe fix and may change runtime behavior
