Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable more Ruff PYI rules with autofixes #12557

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We noqa that one twice in nanoid stubs for the paramether alphabet: str = "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

Ruff issue for the bad autofix in Literal: astral-sh/ruff#12995

# "PYI054", Numeric literals with a string representation longer than ten characters are not permitted
]
extend-safe-fixes = [
"UP036", # Remove unnecessary `sys.version_info` blocks
Expand Down
1 change: 1 addition & 0 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: PYI036 # This is the module declaring BaseException
import _ast
import _typeshed
import sys
Expand Down