From dec89bc79b53547888db5668cf19ac33a383ab92 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Mon, 9 Oct 2023 14:17:58 +0200 Subject: [PATCH 1/6] gh-110558: Run ruff on Argument Clinic in CI --- .pre-commit-config.yaml | 4 ++++ Tools/clinic/.ruff.toml | 14 ++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 Tools/clinic/.ruff.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a5d32a04fc2d7d..69a754242de0ee 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,6 +6,10 @@ repos: name: Run Ruff on Lib/test/ args: [--exit-non-zero-on-fix] files: ^Lib/test/ + - id: ruff + name: Run Ruff on Tools/clinic/ + args: [--exit-non-zero-on-fix] + files: ^Tools/clinic/ - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 diff --git a/Tools/clinic/.ruff.toml b/Tools/clinic/.ruff.toml new file mode 100644 index 00000000000000..163c2381cd47f9 --- /dev/null +++ b/Tools/clinic/.ruff.toml @@ -0,0 +1,14 @@ +target-version = "py310" +fix = true +select = [ + "F", # Enable all pyflakes rules + "RUF100", # Ban unused `# noqa` comments + "PGH004", # Ban blanket `# noqa` comments (only ignore specific error codes) +] +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", + "F601", + "F602", +] From b52e2d4f8a88b3b957999cefb5cef04a8c6f4ad9 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Mon, 9 Oct 2023 14:19:21 +0200 Subject: [PATCH 2/6] Fix pyflakes complaints --- Tools/clinic/clinic.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index eca4747a3e4d57..71f454ad0a3796 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -924,7 +924,6 @@ def compiler_deprecated_warning( # Format the preprocessor warning and error messages. assert isinstance(self.cpp.filename, str) - source = os.path.basename(self.cpp.filename) message = f"Update the clinic input of {func.full_name!r}." code = self.COMPILER_DEPRECATION_WARNING_PROTOTYPE.format( major=minversion[0], @@ -1847,7 +1846,6 @@ def render_function( first_optional = len(selfless) positional = selfless and selfless[-1].is_positional_only() new_or_init = f.kind.new_or_init - has_option_groups = False # offset i by -1 because first_optional needs to ignore self for i, p in enumerate(parameters, -1): @@ -6343,7 +6341,6 @@ def check_remaining_star(self, lineno: int | None = None) -> None: else: return - no_param_after_symbol = True for p in reversed(self.function.parameters.values()): if self.keyword_only: if p.kind == inspect.Parameter.KEYWORD_ONLY: From ead758746e6868ef00876b22fb40c5230a88835d Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Mon, 9 Oct 2023 14:22:11 +0200 Subject: [PATCH 3/6] also fix a ruff deprecation warning regarding an environment variable, while we're here --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 89f65816b6969d..6c1c29a58cf4fc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,7 +7,7 @@ permissions: env: FORCE_COLOR: 1 - RUFF_FORMAT: github + RUFF_OUTPUT_FORMAT: github concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} From 75c7a56f164d0fc3149e32bc42d7c0e7d2a7debc Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 9 Oct 2023 14:24:49 +0200 Subject: [PATCH 4/6] oops i deleted the wrong variable --- Tools/clinic/clinic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 71f454ad0a3796..0f26350e1d0623 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -1845,7 +1845,7 @@ def render_function( last_group = 0 first_optional = len(selfless) positional = selfless and selfless[-1].is_positional_only() - new_or_init = f.kind.new_or_init + has_option_groups = False # offset i by -1 because first_optional needs to ignore self for i, p in enumerate(parameters, -1): From 485c5485df9e8a219b4913eecf996d143c3846e8 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Mon, 9 Oct 2023 14:28:59 +0200 Subject: [PATCH 5/6] comments --- Tools/clinic/.ruff.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tools/clinic/.ruff.toml b/Tools/clinic/.ruff.toml index 163c2381cd47f9..3bc9d908ed3296 100644 --- a/Tools/clinic/.ruff.toml +++ b/Tools/clinic/.ruff.toml @@ -8,7 +8,7 @@ select = [ 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", - "F601", - "F602", + "F841", # Detects unused variables + "F601", # Detects dictionaries that have duplicate keys + "F602", # Also detects dictionaries that have duplicate keys ] From 5850844afa3a02901ae1028d8b9699308802b840 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Tue, 10 Oct 2023 09:21:22 +0200 Subject: [PATCH 6/6] Also run all the pyflakes checks on `Lib/test/test_clinic.py` --- .pre-commit-config.yaml | 4 ++-- Lib/test/.ruff.toml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 69a754242de0ee..da96855c7f6b72 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,8 +8,8 @@ repos: files: ^Lib/test/ - id: ruff name: Run Ruff on Tools/clinic/ - args: [--exit-non-zero-on-fix] - files: ^Tools/clinic/ + args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml] + files: ^Tools/clinic/|Lib/test/test_clinic.py - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 diff --git a/Lib/test/.ruff.toml b/Lib/test/.ruff.toml index f4e68eba14068d..424c81f6ecd759 100644 --- a/Lib/test/.ruff.toml +++ b/Lib/test/.ruff.toml @@ -3,6 +3,8 @@ select = [ "F811", # Redefinition of unused variable (useful for finding test methods with the same name) ] extend-exclude = [ + # Excluded (run with the other AC files in its own separate ruff job in pre-commit) + "test_clinic.py", # Excluded (these aren't actually executed, they're just "data files") "tokenizedata/*.py", # Failed to lint