We start to addopt ruff in Tools/ gradually, many folders already have some level of support:
|
name: Run Ruff (lint) on Doc/ |
|
args: [--exit-non-zero-on-fix] |
|
files: ^Doc/ |
|
- id: ruff |
|
name: Run Ruff (lint) on Lib/test/ |
|
args: [--exit-non-zero-on-fix] |
|
files: ^Lib/test/ |
|
- id: ruff |
|
name: Run Ruff (lint) on Tools/build/ |
|
args: [--exit-non-zero-on-fix, --config=Tools/build/.ruff.toml] |
|
files: ^Tools/build/ |
|
- id: ruff |
|
name: Run Ruff (lint) on Argument Clinic |
|
args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml] |
|
files: ^Tools/clinic/|Lib/test/test_clinic.py |
|
- id: ruff-format |
|
name: Run Ruff (format) on Doc/ |
|
args: [--check] |
|
files: ^Doc/ |
|
- id: ruff-format |
|
name: Run Ruff (format) on Tools/build/check_warnings.py |
|
args: [--check, --config=Tools/build/.ruff.toml] |
|
files: ^Tools/build/check_warnings.py |
I propose adding this config to Tools/peg_generator:
extend = "../../.ruff.toml" # Inherit the project-wide settings
extend-exclude = [
# Generated files:
"pegen/grammar_parser.py",
]
[lint]
select = [
"F", # Enable all pyflakes rules
"I", # Enable all isort rules
"UP", # Enable all pyupgrade rules by default
"RUF100", # Ban unused `# noqa` comments
"PGH004", # Ban blanket `# noqa` comments (only ignore specific error codes)
]
ignore = [
# Unnecessary parentheses to functools.lru_cache: just leads to unnecessary churn.
# https://github.com/python/cpython/pull/104684#discussion_r1199653347.
"UP011",
# Use format specifiers instead of %-style formatting.
# Doesn't always make code more readable.
"UP031",
# Use f-strings instead of format specifiers.
# Doesn't always make code more readable.
"UP032",
# Use PEP-604 unions rather than tuples for isinstance() checks.
# Makes code slower and more verbose. https://github.com/astral-sh/ruff/issues/7871.
"UP038",
]
unfixable = [
# The autofixes sometimes do the wrong things for these;
# it's better to have to manually look at the code and see how it needs fixing
"F841", # Detects unused variables
"F601", # Detects dictionaries that have duplicate keys
"F602", # Also detects dictionaries that have duplicate keys
]
It is based on https://github.com/python/cpython/blob/main/Tools/clinic/.ruff.toml
I've double checked the changed produced by it and did not find anything problematic.
So, let's give this a try!
Linked PRs
We start to addopt
ruffinTools/gradually, many folders already have some level of support:cpython/.pre-commit-config.yaml
Lines 6 to 28 in 4357302
I propose adding this config to
Tools/peg_generator:It is based on https://github.com/python/cpython/blob/main/Tools/clinic/.ruff.toml
I've double checked the changed produced by it and did not find anything problematic.
So, let's give this a try!
Linked PRs
ruffonTools/peg_generator#138282ruffonTools/peg_generator(GH-138282) #138469ruffonTools/peg_generator(GH-138282) #138472topsortand bump minimal version inpeg_generator#138487