Skip to content

Enable Ruff preview and use human-readable rule names - #16496

Merged
AlexWaygood merged 4 commits into
mainfrom
alex/human-readable-names
Oct 7, 2026
Merged

AlexWaygood merged 4 commits into
mainfrom
alex/human-readable-names

Conversation

@AlexWaygood

@AlexWaygood AlexWaygood commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

This PR enables preview = true in our Ruff config. The main motivation for this is so that we can use human-readable rule names in the configuration and suppression comments, making both much easier to read.

Ruff's preview mode also enables some additional rules under our current configuration, and enables some preview-only changes in some existing rules.

Full changes made:

  • Convert individual rule codes and Ruff-specific # noqa suppressions to rule names, while preserving suppressions for other linters.
  • Enable quoted-type-alias. We previously had a TODO for this rule in our config, saying we should enable it after it came out of preview.
  • Ignore import-private-name globally because it produced false positives
  • Exclude redefined-slots-in-subclass and ambiguous-unicode-character-string for stubs, which need to represent runtime objects and values faithfully.

Prepared using Codex.

@AlexWaygood AlexWaygood changed the title Enable Ruff preview and use human-readable rule names Enable Ruff preview and use human-readable rule names Oct 7, 2026

@AlexWaygood AlexWaygood Oct 7, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ruff flagged the old @cached_property/@abstractmethod combination under incorrect-decorator-order, a preview-only rule. In the pinned 2026.08.19 source, info is a cached property that calls the abstract _info method, which is implemented by each runtime.

Comment on lines -1 to +3
### This .pyi file is a helper for centralized storage types that are reused across different runtime modules. ###
############################################################################################################
# This .pyi file is a helper for centralized storage types that are reused across different runtime modules.
############################################################################################################

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ruff flagged the old version of this comment with https://docs.astral.sh/ruff/rules/multiple-leading-hashes-for-block-comment/

@github-actions

This comment has been minimized.

Comment thread stdlib/builtins.pyi
Comment on lines 93 to +99
_StartT_co = TypeVar("_StartT_co", covariant=True, default=Any) # slice -> slice[Any, Any, Any]
_StopT_co = TypeVar("_StopT_co", covariant=True, default=_StartT_co) # slice[A] -> slice[A, A, A]
_StopT_co = TypeVar("_StopT_co", covariant=True, default=_StartT_co) # slice[A] -> slice[A, A, A]
# NOTE: step could differ from start and stop, (e.g. datetime/timedelta)l
# the default (start|stop) is chosen to cater to the most common case of int/index slices.
# FIXME: https://github.com/python/typing/issues/213 (replace step=start|stop with step=start&stop)
_StepT_co = TypeVar("_StepT_co", covariant=True, default=_StartT_co | _StopT_co) # slice[A,B] -> slice[A, B, A|B]
_StepT_co = TypeVar("_StepT_co", covariant=True, default=_StartT_co | _StopT_co) # slice[A,B] -> slice[A, B, A|B]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

these changes were due to an autofix by no-space-after-inline-comment, which also flags too many spaces after an inline comment #

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau

srittau commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

The main motivation for this is so that we can use human-readable rule names in the configuration and suppression comments, making both much easier to read.

Big +1 for that. As someone with a terrible memory, I always preferred the eslint-style over the obscure pylint-style error codes.

I assume preview mode is mostly temporary and we will disable it when the current feature set makes it to non-preview ruff? (Of course with the option to re-enable it if necessary.)

@AlexWaygood
AlexWaygood marked this pull request as ready for review October 7, 2026 12:49
@AlexWaygood

AlexWaygood commented Oct 7, 2026 •

Copy link
Copy Markdown
Member Author

I assume preview mode is mostly temporary and we will disable it when the current feature set makes it to non-preview ruff? (Of course with the option to re-enable it if necessary.)

Yes, exactly. I don't think it makes too much sense for us to be on the bleeding edge of Ruff's lint rules long-term, but for this feature... I really want ASAP 😃

Comment thread pyproject.toml
"TC010", # Invalid string member in `X | Y`-style union type
"runtime-import-in-type-checking-block", # Move import `{qualified_name}` out of type-checking block. Import is used for more than type hinting.
"empty-type-checking-block",
"quoted-type-alias",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

newly enabled, note that it was commented out with a TODO comment before saying to enable it when it was out of preview

Comment thread pyproject.toml
Comment on lines +244 to +247
# Runtime classes may redefine inherited slots, which their stubs need to preserve.
"redefined-slots-in-subclass",
# String literals in stubs must sometimes match runtime values containing confusable Unicode.
"ambiguous-unicode-character-string",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

newly disabled, I think they're preview-only. Both had false positives on our stubs

Comment thread pyproject.toml
Comment on lines +208 to +209
# Stubs need private imports to describe runtime APIs; our scripts also import local private modules such as `_utils`.
"import-private-name",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

previously this was only disabled for stubs; it's now disabled globally. It was flagging imports of _utils in our lib package we use for our tests and scripts

@AlexWaygood
AlexWaygood merged commit 3b003a6 into main Oct 7, 2026
96 checks passed
@AlexWaygood
AlexWaygood deleted the alex/human-readable-names branch October 7, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants