Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ruff] Improve the diagnostic for RUF012#23202

Merged
ntBre merged 1 commit intomainfrom
brent/ruf012-message
Feb 10, 2026
Merged

[ruff] Improve the diagnostic for RUF012#23202
ntBre merged 1 commit intomainfrom
brent/ruf012-message

Conversation

@ntBre
Copy link
Contributor

@ntBre ntBre commented Feb 10, 2026

Summary

The existing diagnostic message for RUF012 suggests annotating the attribute
with typing.ClassVar, even though the usual fix is actually initializing the
field in __init__. This PR shortens the main message and moves both of these
suggestions into the fix title, which is still displayed despite the rule having
no fix.

I also considered making the message more similar to B006:

Do not use mutable data structures for argument defaults

but I kind of preferred my phrasing here.

Test Plan

Updated existing snapshots

Summary
--

The existing diagnostic message for `RUF012` suggests annotating the attribute
with `typing.ClassVar`, even though the usual fix is actually initializing the
field in `__init__`. This PR shortens the main message and moves both of these
suggestions into the fix title, which is still displayed despite the rule having
no fix.

I also considered making the message more similar to `B006`:

> Do not use mutable data structures for argument defaults

but I kind of preferred my phrasing here.

Test Plan
--

Updated existing snapshots
@ntBre ntBre added the diagnostics Related to reporting of diagnostics. label Feb 10, 2026
Copy link
Contributor

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

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

Thank you for taking my feedback seriously! (someone who actually knows about ruff should probably review this as well 😄)

@ntBre ntBre requested a review from amyreese February 10, 2026 15:28
@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 10, 2026

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+3224 -3224 violations, +0 -0 fixes in 6 projects; 50 projects unchanged)

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

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

- airflow-core/docs/empty_plugin/empty_plugin.py:56:24: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ airflow-core/docs/empty_plugin/empty_plugin.py:56:24: RUF012 Mutable default value for class attribute
- airflow-core/docs/empty_plugin/empty_plugin.py:57:24: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ airflow-core/docs/empty_plugin/empty_plugin.py:57:24: RUF012 Mutable default value for class attribute
- airflow-core/src/airflow/api_fastapi/common/exceptions.py:59:72: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ airflow-core/src/airflow/api_fastapi/common/exceptions.py:59:72: RUF012 Mutable default value for class attribute
- airflow-core/src/airflow/api_fastapi/core_api/datamodels/backfills.py:36:26: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ airflow-core/src/airflow/api_fastapi/core_api/datamodels/backfills.py:36:26: RUF012 Mutable default value for class attribute
- airflow-core/src/airflow/configuration.py:277:68: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ airflow-core/src/airflow/configuration.py:277:68: RUF012 Mutable default value for class attribute
... 1220 additional changes omitted for project

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

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

- docker/pythonpath_dev/superset_config.py:94:21: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ docker/pythonpath_dev/superset_config.py:94:21: RUF012 Mutable default value for class attribute
- superset/advanced_data_type/api.py:46:33: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ superset/advanced_data_type/api.py:46:33: RUF012 Mutable default value for class attribute
- superset/annotation_layers/annotations/api.py:100:21: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ superset/annotation_layers/annotations/api.py:100:21: RUF012 Mutable default value for class attribute
- superset/annotation_layers/annotations/api.py:110:22: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ superset/annotation_layers/annotations/api.py:110:22: RUF012 Mutable default value for class attribute
- superset/annotation_layers/annotations/api.py:112:33: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ superset/annotation_layers/annotations/api.py:112:33: RUF012 Mutable default value for class attribute
... 1012 additional changes omitted for project

binary-husky/gpt_academic (+28 -28 violations, +0 -0 fixes)

- crazy_functions/doc_fns/read_fns/excel_reader.py:36:38: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ crazy_functions/doc_fns/read_fns/excel_reader.py:36:38: RUF012 Mutable default value for class attribute
- crazy_functions/doc_fns/read_fns/markitdown/markdown_reader.py:56:38: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ crazy_functions/doc_fns/read_fns/markitdown/markdown_reader.py:56:38: RUF012 Mutable default value for class attribute
- crazy_functions/doc_fns/read_fns/unstructured_all/paper_metadata_extractor.py:53:38: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ crazy_functions/doc_fns/read_fns/unstructured_all/paper_metadata_extractor.py:53:38: RUF012 Mutable default value for class attribute
- crazy_functions/doc_fns/read_fns/unstructured_all/paper_metadata_extractor.py:60:24: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ crazy_functions/doc_fns/read_fns/unstructured_all/paper_metadata_extractor.py:60:24: RUF012 Mutable default value for class attribute
- crazy_functions/doc_fns/read_fns/unstructured_all/paper_structure_extractor.py:94:30: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ crazy_functions/doc_fns/read_fns/unstructured_all/paper_structure_extractor.py:94:30: RUF012 Mutable default value for class attribute
... 46 additional changes omitted for project

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

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

- examples/advanced/extensions/font-awesome/fontawesome_icon.py:11:24: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ examples/advanced/extensions/font-awesome/fontawesome_icon.py:11:24: RUF012 Mutable default value for class attribute
- examples/advanced/extensions/widget.py:15:22: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ examples/advanced/extensions/widget.py:15:22: RUF012 Mutable default value for class attribute
- src/bokeh/application/handlers/code.py:74:21: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ src/bokeh/application/handlers/code.py:74:21: RUF012 Mutable default value for class attribute
- src/bokeh/core/property/visual.py:81:22: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ src/bokeh/core/property/visual.py:81:22: RUF012 Mutable default value for class attribute
- src/bokeh/document/models.py:68:32: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ src/bokeh/document/models.py:68:32: RUF012 Mutable default value for class attribute
... 54 additional changes omitted for project

latchbio/latch (+1 -1 violations, +0 -0 fixes)

- src/latch_cli/centromere/utils.py:73:23: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ src/latch_cli/centromere/utils.py:73:23: RUF012 Mutable default value for class attribute

zulip/zulip (+2037 -2037 violations, +0 -0 fixes)

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

- analytics/migrations/0001_initial.py:12:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0001_initial.py:12:18: RUF012 Mutable default value for class attribute
- analytics/migrations/0001_initial.py:7:20: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0001_initial.py:7:20: RUF012 Mutable default value for class attribute
- analytics/migrations/0001_squashed_0021_alter_fillstate_id.py:35:20: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0001_squashed_0021_alter_fillstate_id.py:35:20: RUF012 Mutable default value for class attribute
- analytics/migrations/0001_squashed_0021_alter_fillstate_id.py:41:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0001_squashed_0021_alter_fillstate_id.py:41:18: RUF012 Mutable default value for class attribute
- analytics/migrations/0001_squashed_0021_alter_fillstate_id.py:9:16: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0001_squashed_0021_alter_fillstate_id.py:9:16: RUF012 Mutable default value for class attribute
- analytics/migrations/0002_remove_huddlecount.py:5:20: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0002_remove_huddlecount.py:5:20: RUF012 Mutable default value for class attribute
- analytics/migrations/0002_remove_huddlecount.py:9:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0002_remove_huddlecount.py:9:18: RUF012 Mutable default value for class attribute
- analytics/migrations/0003_fillstate.py:5:20: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0003_fillstate.py:5:20: RUF012 Mutable default value for class attribute
- analytics/migrations/0003_fillstate.py:9:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0003_fillstate.py:9:18: RUF012 Mutable default value for class attribute
- analytics/migrations/0004_add_subgroup.py:5:20: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0004_add_subgroup.py:5:20: RUF012 Mutable default value for class attribute
- analytics/migrations/0004_add_subgroup.py:9:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0004_add_subgroup.py:9:18: RUF012 Mutable default value for class attribute
- analytics/migrations/0005_alter_field_size.py:5:20: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0005_alter_field_size.py:5:20: RUF012 Mutable default value for class attribute
- analytics/migrations/0005_alter_field_size.py:9:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0005_alter_field_size.py:9:18: RUF012 Mutable default value for class attribute
- analytics/migrations/0006_add_subgroup_to_unique_constraints.py:5:20: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0006_add_subgroup_to_unique_constraints.py:5:20: RUF012 Mutable default value for class attribute
- analytics/migrations/0006_add_subgroup_to_unique_constraints.py:9:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0006_add_subgroup_to_unique_constraints.py:9:18: RUF012 Mutable default value for class attribute
- analytics/migrations/0007_remove_interval.py:10:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
... 4043 additional changes omitted for project

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
RUF012 6448 3224 3224 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+3224 -3224 violations, +0 -0 fixes in 6 projects; 50 projects unchanged)

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

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

- airflow-core/docs/empty_plugin/empty_plugin.py:56:24: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ airflow-core/docs/empty_plugin/empty_plugin.py:56:24: RUF012 Mutable default value for class attribute
- airflow-core/docs/empty_plugin/empty_plugin.py:57:24: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ airflow-core/docs/empty_plugin/empty_plugin.py:57:24: RUF012 Mutable default value for class attribute
- airflow-core/src/airflow/api_fastapi/common/exceptions.py:59:72: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ airflow-core/src/airflow/api_fastapi/common/exceptions.py:59:72: RUF012 Mutable default value for class attribute
- airflow-core/src/airflow/api_fastapi/core_api/datamodels/backfills.py:36:26: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ airflow-core/src/airflow/api_fastapi/core_api/datamodels/backfills.py:36:26: RUF012 Mutable default value for class attribute
- airflow-core/src/airflow/configuration.py:277:68: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ airflow-core/src/airflow/configuration.py:277:68: RUF012 Mutable default value for class attribute
... 1220 additional changes omitted for project

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

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

- docker/pythonpath_dev/superset_config.py:94:21: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ docker/pythonpath_dev/superset_config.py:94:21: RUF012 Mutable default value for class attribute
- superset/advanced_data_type/api.py:46:33: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ superset/advanced_data_type/api.py:46:33: RUF012 Mutable default value for class attribute
- superset/annotation_layers/annotations/api.py:100:21: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ superset/annotation_layers/annotations/api.py:100:21: RUF012 Mutable default value for class attribute
- superset/annotation_layers/annotations/api.py:110:22: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ superset/annotation_layers/annotations/api.py:110:22: RUF012 Mutable default value for class attribute
- superset/annotation_layers/annotations/api.py:112:33: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ superset/annotation_layers/annotations/api.py:112:33: RUF012 Mutable default value for class attribute
... 1012 additional changes omitted for project

binary-husky/gpt_academic (+28 -28 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- crazy_functions/doc_fns/read_fns/excel_reader.py:36:38: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ crazy_functions/doc_fns/read_fns/excel_reader.py:36:38: RUF012 Mutable default value for class attribute
- crazy_functions/doc_fns/read_fns/markitdown/markdown_reader.py:56:38: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ crazy_functions/doc_fns/read_fns/markitdown/markdown_reader.py:56:38: RUF012 Mutable default value for class attribute
- crazy_functions/doc_fns/read_fns/unstructured_all/paper_metadata_extractor.py:53:38: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ crazy_functions/doc_fns/read_fns/unstructured_all/paper_metadata_extractor.py:53:38: RUF012 Mutable default value for class attribute
- crazy_functions/doc_fns/read_fns/unstructured_all/paper_metadata_extractor.py:60:24: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ crazy_functions/doc_fns/read_fns/unstructured_all/paper_metadata_extractor.py:60:24: RUF012 Mutable default value for class attribute
- crazy_functions/doc_fns/read_fns/unstructured_all/paper_structure_extractor.py:94:30: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ crazy_functions/doc_fns/read_fns/unstructured_all/paper_structure_extractor.py:94:30: RUF012 Mutable default value for class attribute
... 46 additional changes omitted for project

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

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

- examples/advanced/extensions/font-awesome/fontawesome_icon.py:11:24: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ examples/advanced/extensions/font-awesome/fontawesome_icon.py:11:24: RUF012 Mutable default value for class attribute
- examples/advanced/extensions/widget.py:15:22: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ examples/advanced/extensions/widget.py:15:22: RUF012 Mutable default value for class attribute
- src/bokeh/application/handlers/code.py:74:21: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ src/bokeh/application/handlers/code.py:74:21: RUF012 Mutable default value for class attribute
- src/bokeh/core/property/visual.py:81:22: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ src/bokeh/core/property/visual.py:81:22: RUF012 Mutable default value for class attribute
- src/bokeh/document/models.py:68:32: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ src/bokeh/document/models.py:68:32: RUF012 Mutable default value for class attribute
... 54 additional changes omitted for project

latchbio/latch (+1 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- src/latch_cli/centromere/utils.py:73:23: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ src/latch_cli/centromere/utils.py:73:23: RUF012 Mutable default value for class attribute

zulip/zulip (+2037 -2037 violations, +0 -0 fixes)

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

- analytics/migrations/0001_initial.py:12:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0001_initial.py:12:18: RUF012 Mutable default value for class attribute
- analytics/migrations/0001_initial.py:7:20: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0001_initial.py:7:20: RUF012 Mutable default value for class attribute
- analytics/migrations/0001_squashed_0021_alter_fillstate_id.py:35:20: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0001_squashed_0021_alter_fillstate_id.py:35:20: RUF012 Mutable default value for class attribute
- analytics/migrations/0001_squashed_0021_alter_fillstate_id.py:41:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0001_squashed_0021_alter_fillstate_id.py:41:18: RUF012 Mutable default value for class attribute
- analytics/migrations/0001_squashed_0021_alter_fillstate_id.py:9:16: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0001_squashed_0021_alter_fillstate_id.py:9:16: RUF012 Mutable default value for class attribute
- analytics/migrations/0002_remove_huddlecount.py:5:20: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0002_remove_huddlecount.py:5:20: RUF012 Mutable default value for class attribute
- analytics/migrations/0002_remove_huddlecount.py:9:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0002_remove_huddlecount.py:9:18: RUF012 Mutable default value for class attribute
- analytics/migrations/0003_fillstate.py:5:20: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0003_fillstate.py:5:20: RUF012 Mutable default value for class attribute
- analytics/migrations/0003_fillstate.py:9:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0003_fillstate.py:9:18: RUF012 Mutable default value for class attribute
- analytics/migrations/0004_add_subgroup.py:5:20: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0004_add_subgroup.py:5:20: RUF012 Mutable default value for class attribute
- analytics/migrations/0004_add_subgroup.py:9:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0004_add_subgroup.py:9:18: RUF012 Mutable default value for class attribute
- analytics/migrations/0005_alter_field_size.py:5:20: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0005_alter_field_size.py:5:20: RUF012 Mutable default value for class attribute
- analytics/migrations/0005_alter_field_size.py:9:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0005_alter_field_size.py:9:18: RUF012 Mutable default value for class attribute
- analytics/migrations/0006_add_subgroup_to_unique_constraints.py:5:20: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0006_add_subgroup_to_unique_constraints.py:5:20: RUF012 Mutable default value for class attribute
- analytics/migrations/0006_add_subgroup_to_unique_constraints.py:9:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
+ analytics/migrations/0006_add_subgroup_to_unique_constraints.py:9:18: RUF012 Mutable default value for class attribute
- analytics/migrations/0007_remove_interval.py:10:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
... 4043 additional changes omitted for project

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
RUF012 6448 3224 3224 0 0

@ntBre ntBre merged commit 3795db1 into main Feb 10, 2026
43 checks passed
@ntBre ntBre deleted the brent/ruf012-message branch February 10, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Related to reporting of diagnostics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants