Skip to content

Commit 26e8c00

Browse files
AvasamAlexWaygood
andauthored
Enable nearly all pyupgrade rules (except on test cases) (#11499)
Co-authored-by: Alex Waygood <[email protected]>
1 parent 5cb2fe9 commit 26e8c00

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

pyproject.toml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ select = [
2828
"B", # flake8-bugbear
2929
"FA", # flake8-future-annotations
3030
"I", # isort
31+
"UP", # pyupgrade
3132
# Only enable rules that have safe autofixes:
3233
"F401", # Remove unused imports
3334
"PYI009", # use `...`, not `pass`, in empty class bodies
@@ -40,14 +41,21 @@ select = [
4041
"PYI032", # use `object`, not `Any`, as the second parameter to `__eq__`
4142
"PYI055", # multiple `type[T]` usages in a union
4243
"PYI058", # use `Iterator` as the return type for `__iter__` methods
43-
"UP004", # Remove explicit `object` inheritance
44-
"UP006", # PEP-585 autofixes
45-
"UP007", # PEP-604 autofixes
46-
"UP013", # Class-based syntax for TypedDicts
47-
"UP014", # Class-based syntax for NamedTuples
48-
"UP019", # Use str over typing.Text
49-
"UP035", # import from typing, not typing_extensions, wherever possible
50-
"UP039", # don't use parens after a class definition with no bases
44+
]
45+
ignore = [
46+
# Slower and more verbose https://github.com/astral-sh/ruff/issues/7871
47+
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
48+
]
49+
50+
[tool.ruff.lint.per-file-ignores]
51+
# Disable "modernization" rules with autofixes from test cases as they often
52+
# deliberately contain code that might not be considered idiomatic or modern
53+
# These can be run manually once in a while
54+
"**/test_cases/**/*.py" = ["UP"]
55+
# Generated protobuf files:
56+
# TODO: Re-run sync_tensorflow_protobuf_stubs.sh with this rule enabled to remove this entry
57+
"*_pb2.pyi" = [
58+
"UP036", # Version block is outdated for minimum Python version
5159
]
5260

5361
[tool.ruff.lint.per-file-ignores]

stubs/six/six/moves/builtins.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
from builtins import *
1+
# flake8: noqa: NQA102 # https://github.com/plinss/flake8-noqa/issues/22
2+
# six explicitly re-exports builtins. Normally this is something we'd want to avoid.
3+
# But this is specifically a compatibility package.
4+
from builtins import * # noqa: UP029

0 commit comments

Comments
 (0)