Repository navigation
Enable Ruff preview and use human-readable rule names - #16496
Conversation
preview and use human-readable rule names
There was a problem hiding this comment.
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.
| ### 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. | ||
| ############################################################################################################ |
There was a problem hiding this comment.
Ruff flagged the old version of this comment with https://docs.astral.sh/ruff/rules/multiple-leading-hashes-for-block-comment/
This comment has been minimized.
This comment has been minimized.
| _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] |
There was a problem hiding this comment.
these changes were due to an autofix by no-space-after-inline-comment, which also flags too many spaces after an inline comment #
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
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.) |
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 😃 |
| "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", |
There was a problem hiding this comment.
newly enabled, note that it was commented out with a TODO comment before saying to enable it when it was out of preview
| # 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", |
There was a problem hiding this comment.
newly disabled, I think they're preview-only. Both had false positives on our stubs
| # Stubs need private imports to describe runtime APIs; our scripts also import local private modules such as `_utils`. | ||
| "import-private-name", |
There was a problem hiding this comment.
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
This PR enables
preview = truein 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:
# noqasuppressions to rule names, while preserving suppressions for other linters.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.import-private-nameglobally because it produced false positivesredefined-slots-in-subclassandambiguous-unicode-character-stringfor stubs, which need to represent runtime objects and values faithfully.Prepared using Codex.