From 4d0e74339c334efb63add04ff102a967b885ef8c Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 19 Aug 2024 13:04:30 -0400 Subject: [PATCH 1/2] Enable more Ruff PYI rules with autofixes --- pyproject.toml | 35 +++++++++++++++++++++++++---------- stdlib/builtins.pyi | 1 + 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 272679e3ef0d..5fb42e707e7f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,16 +48,31 @@ select = [ "W", # pycodestyle Warning # PYI: only enable rules that always autofix, avoids duplicate # noqa with flake8-pyi # See https://github.com/plinss/flake8-noqa/issues/22 - "PYI009", # use `...`, not `pass`, in empty class bodies - "PYI010", # function bodies must be empty - "PYI012", # class bodies must not contain `pass` - "PYI013", # non-empty class bodies must not contain `...` - "PYI016", # duplicate union member - "PYI020", # quoted annotations are always unnecessary in stubs - "PYI025", # always alias `collections.abc.Set` as `AbstractSet` when importing it - "PYI032", # use `object`, not `Any`, as the second parameter to `__eq__` - "PYI055", # multiple `type[T]` usages in a union - "PYI058", # use `Iterator` as the return type for `__iter__` methods + "PYI009", # Empty body should contain `...`, not pass + "PYI010", # Function body must contain only `...` + "PYI012", # Class bodies must not contain `pass` + "PYI014", # Only simple default values allowed for arguments + "PYI015", # Only simple default values allowed for assignments + "PYI020", # Quoted annotations should not be included in stubs + "PYI032", # Prefer `object` to `Any` for the second parameter to `{method_name}` + "PYI058", # Use `{return_type}` as the return value for simple `{method}` methods + # PYI rules that sometimes autofix, but we should always be able to manually fix, + # so there's still no conflict/duplicate with flake8-pyi + "PYI013", # Non-empty class bodies must not contain `...` + "PYI016", # Duplicate union member `{}` + "PYI025", # Use `from collections.abc import Set as AbstractSet` to avoid confusion with the `set` builtin + "PYI030", # Multiple literal members in a union. Use a single literal, e.g. `Literal[{}]` + "PYI036", # Star-args in `{method_name}` should be annotated with `object` + "PYI044", # `from __future__ import annotations` has no effect in stub files, since type checkers automatically treat stubs as having those semantics + "PYI055", # Multiple `type[T]` usages in a union. Combine them into one, e.g., `type[{union_str}]`. + "PYI062", # Duplicate literal member `{}` + # Rules that have autofixes, but we sometimes disable on a per-line basis + # "PYI026", Waiting for this mypy bug to be fixed: https://github.com/python/mypy/issues/16581 + # "PYI029", __str__ and __str__ sometimes have to be used for classes other than `object` + # Sometimes we still wanna be explicit about a default value nonetheless + # "PYI011", Also has false-positives with `_typeshed.sentinel` + # "PYI053", Also removes `Literal[{string_too_long}]` from an annotation + # "PYI054", Numeric literals with a string representation longer than ten characters are not permitted ] extend-safe-fixes = [ "UP036", # Remove unnecessary `sys.version_info` blocks diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 95335d241ea1..769ef8f2006a 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1,3 +1,4 @@ +# ruff: noqa: PYI036 # This is the module declaring BaseException import _ast import _typeshed import sys From 9922b2f9e61948e0215ab65a2086e3e18ce05cfe Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 19 Aug 2024 13:12:57 -0400 Subject: [PATCH 2/2] Keep in 1 group --- pyproject.toml | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5fb42e707e7f..6483bb197410 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,33 +46,26 @@ select = [ "E", # pycodestyle Error "F", # Pyflakes "W", # pycodestyle Warning - # PYI: only enable rules that always autofix, avoids duplicate # noqa with flake8-pyi + # PYI: only enable rules that have autofixes and that we always want to fix (even manually), + # avoids duplicate # noqa with flake8-pyi and flake8-noqa flagging `PYI` codes # See https://github.com/plinss/flake8-noqa/issues/22 "PYI009", # Empty body should contain `...`, not pass "PYI010", # Function body must contain only `...` "PYI012", # Class bodies must not contain `pass` + "PYI013", # Non-empty class bodies must not contain `...` "PYI014", # Only simple default values allowed for arguments "PYI015", # Only simple default values allowed for assignments - "PYI020", # Quoted annotations should not be included in stubs - "PYI032", # Prefer `object` to `Any` for the second parameter to `{method_name}` - "PYI058", # Use `{return_type}` as the return value for simple `{method}` methods - # PYI rules that sometimes autofix, but we should always be able to manually fix, - # so there's still no conflict/duplicate with flake8-pyi - "PYI013", # Non-empty class bodies must not contain `...` "PYI016", # Duplicate union member `{}` + "PYI020", # Quoted annotations should not be included in stubs "PYI025", # Use `from collections.abc import Set as AbstractSet` to avoid confusion with the `set` builtin + # "PYI026", Waiting for this mypy bug to be fixed: https://github.com/python/mypy/issues/16581 "PYI030", # Multiple literal members in a union. Use a single literal, e.g. `Literal[{}]` + "PYI032", # Prefer `object` to `Any` for the second parameter to `{method_name}` "PYI036", # Star-args in `{method_name}` should be annotated with `object` "PYI044", # `from __future__ import annotations` has no effect in stub files, since type checkers automatically treat stubs as having those semantics "PYI055", # Multiple `type[T]` usages in a union. Combine them into one, e.g., `type[{union_str}]`. + "PYI058", # Use `{return_type}` as the return value for simple `{method}` methods "PYI062", # Duplicate literal member `{}` - # Rules that have autofixes, but we sometimes disable on a per-line basis - # "PYI026", Waiting for this mypy bug to be fixed: https://github.com/python/mypy/issues/16581 - # "PYI029", __str__ and __str__ sometimes have to be used for classes other than `object` - # Sometimes we still wanna be explicit about a default value nonetheless - # "PYI011", Also has false-positives with `_typeshed.sentinel` - # "PYI053", Also removes `Literal[{string_too_long}]` from an annotation - # "PYI054", Numeric literals with a string representation longer than ten characters are not permitted ] extend-safe-fixes = [ "UP036", # Remove unnecessary `sys.version_info` blocks