Skip to content

[flake8-self] Ignore attribute accesses on instance-like variables (SLF001)#16149

Merged
MichaReiser merged 4 commits intoastral-sh:mainfrom
InSyncWithFoo:SLF001
Feb 23, 2025
Merged

[flake8-self] Ignore attribute accesses on instance-like variables (SLF001)#16149
MichaReiser merged 4 commits intoastral-sh:mainfrom
InSyncWithFoo:SLF001

Conversation

@InSyncWithFoo
Copy link
Copy Markdown
Contributor

@InSyncWithFoo InSyncWithFoo commented Feb 14, 2025

Summary

Resolves #9022.

SLF001 now recognizes the following as instance-like and will not report them:

  • cls()/mcs()
  • super().__new__()
  • SameClass()/SameClass[int]()/Annotated[SameClass[int], ...]()
  • a: SameClass/a: SameClass[int]/a: Annotated[SameClass[int], ...]

The new logic prioritizes avoiding false positives over avoiding false negatives. As the issue is labeled as a bug, the changes are not preview-gated.

Test Plan

cargo nextest run and cargo insta test.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 14, 2025

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+0 -14 violations, +0 -0 fixes in 3 projects; 52 projects unchanged)

apache/airflow (+0 -6 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --no-preview --select ALL

- airflow/io/path.py:365:17: SLF001 Private member accessed: `_cp_file`
- airflow/models/serialized_dag.py:218:36: SLF001 Private member accessed: `_data`
- airflow/models/serialized_dag.py:219:47: SLF001 Private member accessed: `_data_compressed`
- airflow/models/taskinstance.py:3084:84: SLF001 Private member accessed: `_execute_task`
- providers/databricks/src/airflow/providers/databricks/hooks/databricks.py:716:13: SLF001 Private member accessed: `_do_api_call`
- task_sdk/src/airflow/sdk/execution_time/supervisor.py:375:9: SLF001 Private member accessed: `_register_pipe_readers`

apache/superset (+0 -3 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --no-preview --select ALL

- superset/migrations/shared/migrate_viz/base.py:127:9: SLF001 Private member accessed: `_pre_action`
- superset/migrations/shared/migrate_viz/base.py:128:9: SLF001 Private member accessed: `_migrate`
- superset/migrations/shared/migrate_viz/base.py:129:9: SLF001 Private member accessed: `_post_action`

bokeh/bokeh (+0 -5 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --no-preview --select ALL

- src/bokeh/model/model.py:105:13: SLF001 Private member accessed: `_id`
- src/bokeh/model/model.py:107:13: SLF001 Private member accessed: `_id`
- src/bokeh/protocol/message.py:200:9: SLF001 Private member accessed: `_header_json`
- src/bokeh/protocol/message.py:201:9: SLF001 Private member accessed: `_metadata_json`
- src/bokeh/protocol/message.py:202:9: SLF001 Private member accessed: `_content_json`

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
SLF001 14 0 14 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+0 -14 violations, +0 -0 fixes in 3 projects; 52 projects unchanged)

apache/airflow (+0 -6 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

- airflow/io/path.py:365:17: SLF001 Private member accessed: `_cp_file`
- airflow/models/serialized_dag.py:218:36: SLF001 Private member accessed: `_data`
- airflow/models/serialized_dag.py:219:47: SLF001 Private member accessed: `_data_compressed`
- airflow/models/taskinstance.py:3084:84: SLF001 Private member accessed: `_execute_task`
- providers/databricks/src/airflow/providers/databricks/hooks/databricks.py:716:13: SLF001 Private member accessed: `_do_api_call`
- task_sdk/src/airflow/sdk/execution_time/supervisor.py:375:9: SLF001 Private member accessed: `_register_pipe_readers`

apache/superset (+0 -3 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

- superset/migrations/shared/migrate_viz/base.py:127:9: SLF001 Private member accessed: `_pre_action`
- superset/migrations/shared/migrate_viz/base.py:128:9: SLF001 Private member accessed: `_migrate`
- superset/migrations/shared/migrate_viz/base.py:129:9: SLF001 Private member accessed: `_post_action`

bokeh/bokeh (+0 -5 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

- src/bokeh/model/model.py:105:13: SLF001 Private member accessed: `_id`
- src/bokeh/model/model.py:107:13: SLF001 Private member accessed: `_id`
- src/bokeh/protocol/message.py:200:9: SLF001 Private member accessed: `_header_json`
- src/bokeh/protocol/message.py:201:9: SLF001 Private member accessed: `_metadata_json`
- src/bokeh/protocol/message.py:202:9: SLF001 Private member accessed: `_content_json`

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
SLF001 14 0 14 0 0

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@InSyncWithFoo
Copy link
Copy Markdown
Contributor Author

Ecosystem changes are all as expected.

Copy link
Copy Markdown
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This looks good to me, but I'd like someone more familiar with the TypeChecker API to have a look too. Maybe @AlexWaygood or @MichaReiser?

@ntBre ntBre added the bug Something isn't working label Feb 14, 2025
Copy link
Copy Markdown
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this overall is an improvement. Will this be a deviation from the upstream rule?

@InSyncWithFoo
Copy link
Copy Markdown
Contributor Author

@MichaReiser This would be a deviation, yes, but the rule already contains multiple such deviations. The upstream rule exempts self, cls, mcs but nothing else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SLF001: access to private field of another instance of the same class

3 participants