Repository navigation
[flake8-self] Allow private access on object.__new__(cls) instances (SLF001) - #29001
Conversation
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| SLF001 | 2 | 0 | 2 | 0 | 0 |
| RUF100 | 1 | 1 | 0 | 0 | 0 |
Linter (preview)
βΉοΈ ecosystem check detected linter changes. (+1 -3 violations, +0 -0 fixes in 2 projects; 56 projects unchanged)
apache/airflow (+0 -2 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --no-fix --output-format concise --preview --select ALL
- task-sdk/src/airflow/sdk/io/path.py:139:9: private-member-access Private member accessed: `_conn_id` - task-sdk/src/airflow/sdk/io/path.py:145:13: private-member-access Private member accessed: `_inject_authenticated_fs`
home-assistant/core (+1 -1 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --no-fix --output-format concise --preview
- homeassistant/config_entries.py:177:41: noqa-comments [*] `noqa` comment used instead of `ruff: ignore` + homeassistant/config_entries.py:177:41: unused-noqa [*] Unused `noqa` directive (unused: `SLF001`)
Changes by rule (3 rules affected)
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| private-member-access | 2 | 0 | 2 | 0 | 0 |
| unused-noqa | 1 | 1 | 0 | 0 | 0 |
| noqa-comments | 1 | 0 | 1 | 0 | 0 |
ntBre
left a comment
There was a problem hiding this comment.
Thanks, this looks good to me overall, just one question.
| arg.as_name_expr().is_some_and(|name| { | ||
| matches!(&*name.id, "cls" | "mcs") | ||
| || Self::is_current_class_name(name, semantic) |
There was a problem hiding this comment.
This same validation could be applied to the super version right? I think I'd either apply it to both or omit this additional change from the PR, and I'd probably lean toward the latter since it's unrelated to the issue.
There was a problem hiding this comment.
Makes sense, I dropped it. super().__new__ and object.__new__ are handled the same way now, with no check on the argument, and I removed the other-class test case.
flake8-self] Allow private access on object.__new__(cls) instances (SLF001)
Summary
Closes #28989
SLF001 already skips instances created with
super().__new__(cls), but not the same pattern written withobject:This extends the special case to
object().__new__(...)andobject.__new__(...), as suggested in the issue.objecthas to resolve to the builtin, andobject()has to be called without arguments.Test Plan
Added cases to
SLF001_1.py: the twoobjectforms withcls,object.__new__(Amet)inside a classmethod, and two that should still be flagged (object(1)and a shadowedobject). The snapshot only gains those two diagnostics.Also checked the reproducer from the issue with a local build: flagged before, clean after.