ruff
4de82976 - [`flake8-self`] Allow private access on `object.__new__(cls)` instances (`SLF001`) (#29001)

Commit
11 days ago
[`flake8-self`] Allow private access on `object.__new__(cls)` instances (`SLF001`) (#29001) ## Summary Closes #28989 SLF001 already skips instances created with `super().__new__(cls)`, but not the same pattern written with `object`: ```python class A: def __new__(cls): obj = object().__new__(cls) obj._private_attr = "bar" # SLF001 before this change ``` This extends the special case to `object().__new__(...)` and `object.__new__(...)`, as suggested in the issue. `object` has to resolve to the builtin, and `object()` has to be called without arguments. ## Test Plan Added cases to `SLF001_1.py`: the two `object` forms with `cls`, `object.__new__(Amet)` inside a classmethod, and two that should still be flagged (`object(1)` and a shadowed `object`). The snapshot only gains those two diagnostics. Also checked the reproducer from the issue with a local build: flagged before, clean after.
Author
Parents
Loading