Skip to content

Commit

Permalink
Enable nearly all pyupgrade rules (except on test cases) (#11499)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Waygood <[email protected]>
  • Loading branch information
Avasam and AlexWaygood authored Feb 29, 2024
1 parent 5cb2fe9 commit 26e8c00
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
24 changes: 16 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ select = [
"B", # flake8-bugbear
"FA", # flake8-future-annotations
"I", # isort
"UP", # pyupgrade
# Only enable rules that have safe autofixes:
"F401", # Remove unused imports
"PYI009", # use `...`, not `pass`, in empty class bodies
Expand All @@ -40,14 +41,21 @@ select = [
"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
"UP004", # Remove explicit `object` inheritance
"UP006", # PEP-585 autofixes
"UP007", # PEP-604 autofixes
"UP013", # Class-based syntax for TypedDicts
"UP014", # Class-based syntax for NamedTuples
"UP019", # Use str over typing.Text
"UP035", # import from typing, not typing_extensions, wherever possible
"UP039", # don't use parens after a class definition with no bases
]
ignore = [
# Slower and more verbose https://github.com/astral-sh/ruff/issues/7871
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
]

[tool.ruff.lint.per-file-ignores]
# Disable "modernization" rules with autofixes from test cases as they often
# deliberately contain code that might not be considered idiomatic or modern
# These can be run manually once in a while
"**/test_cases/**/*.py" = ["UP"]
# Generated protobuf files:
# TODO: Re-run sync_tensorflow_protobuf_stubs.sh with this rule enabled to remove this entry
"*_pb2.pyi" = [
"UP036", # Version block is outdated for minimum Python version
]

[tool.ruff.lint.per-file-ignores]
Expand Down
5 changes: 4 additions & 1 deletion stubs/six/six/moves/builtins.pyi
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from builtins import *
# flake8: noqa: NQA102 # https://github.com/plinss/flake8-noqa/issues/22
# six explicitly re-exports builtins. Normally this is something we'd want to avoid.
# But this is specifically a compatibility package.
from builtins import * # noqa: UP029

0 comments on commit 26e8c00

Please sign in to comment.