Enable Ruff PLC (Pylint Convention)#13306
Merged
srittau merged 12 commits intopython:mainfrom Mar 3, 2025
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Avasam
commented
Dec 26, 2024
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
srittau
approved these changes
Feb 26, 2025
Collaborator
|
boltons now needs fixes as well. Can be merged when that is fixed. (Unfortunately I don't have permissions to make these changes myself.) |
This comment has been minimized.
This comment has been minimized.
Avasam
commented
Mar 2, 2025
Comment on lines
-162
to
+179
| # Most pep8-naming rules don't apply for third-party stubs like typeshed. | ||
| # N811 to N814 could apply, but we often use them to disambiguate a name whilst making it look like a more common one | ||
| "N8", | ||
| # Ruff 0.8.0 added sorting of __all__ and __slots_. | ||
| # There is no consensus on whether we want to apply this to stubs, so keeping the status quo. | ||
| # See https://github.com/python/typeshed/pull/13108 | ||
| "RUF022", # `__all__` is not sorted | ||
| "RUF023", # `{}.__slots__` is not sorted | ||
| ### | ||
| # Rules that are out of the control of stub authors: | ||
| ### | ||
| "F403", # `from . import *` used; unable to detect undefined names | ||
| # Stubs can sometimes re-export entire modules. | ||
| # Issues with using a star-imported name will be caught by type-checkers. | ||
| "F405", # may be undefined, or defined from star imports | ||
| # Ruff 0.8.0 added sorting of __all__ and __slots_. | ||
| # There is no consensus on whether we want to apply this to stubs, so keeping the status quo. | ||
| # See https://github.com/python/typeshed/pull/13108 | ||
| "RUF022", | ||
| "RUF023", | ||
| # Most pep8-naming rules don't apply for third-party stubs like typeshed. | ||
| # N811 to N814 could apply, but we often use them to disambiguate a name whilst making it look like a more common one | ||
| "N8", # pep8-naming | ||
| "PLC2701", # Private name import from external module | ||
| ] |
Collaborator
Author
There was a problem hiding this comment.
All this is just moving some rules so they appear in the right section and are in alphabetical order. Technically not directly related to this PR.
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: pyinstrument (https://github.com/joerick/pyinstrument)
- pyinstrument/vendor/decorator.py:295: error: Incompatible types in assignment (expression has type "Callable[[Any, Any, VarArg(Any), KwArg(Any)], Any]", variable has type "Callable[[_GeneratorContextManagerBase[_G], Callable[..., _G], tuple[Any, ...], dict[str, Any]], None]") [assignment]
+ pyinstrument/vendor/decorator.py:295: error: Incompatible types in assignment (expression has type "Callable[[Any, Any, VarArg(Any), KwArg(Any)], Any]", variable has type "Callable[[_GeneratorContextManagerBase[_G_co], Callable[..., _G_co], tuple[Any, ...], dict[str, Any]], None]") [assignment]
- pyinstrument/vendor/decorator.py:301: error: Incompatible types in assignment (expression has type "Callable[[Any, Any, VarArg(Any), KwArg(Any)], Any]", variable has type "Callable[[_GeneratorContextManagerBase[_G], Callable[..., _G], tuple[Any, ...], dict[str, Any]], None]") [assignment]
+ pyinstrument/vendor/decorator.py:301: error: Incompatible types in assignment (expression has type "Callable[[Any, Any, VarArg(Any), KwArg(Any)], Any]", variable has type "Callable[[_GeneratorContextManagerBase[_G_co], Callable[..., _G_co], tuple[Any, ...], dict[str, Any]], None]") [assignment]
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ref #13295
https://docs.astral.sh/ruff/rules/#convention-c
The only stub changes are flagged by type-name-incorrect-variance (PLC0105), which enforces the
_co/_contrasuffix. Which we didn't consistently do. Even sometimes incorrectly suffixed.import-private-name (PLC2701) is still in preview, so we're not affected yet, but typeshed uses many private imports in its stubs to reference types accurately. I don't think this rule applies to our stubs.
It's unclear whether Ruff should consider disabling it for stubs entirely, but it's mentioned here: astral-sh/ruff#14535