From 6eb70de0baf0e41fa8f25f96d24cc70010eebf3e Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Sat, 29 Aug 2026 12:01:52 +0200 Subject: [PATCH] Key the pre-commit cache on the Python that was actually installed The key said `py3.12` as a literal while the job installs `3.x`, which is 3.14.7 today. A `language: python` hook env is built by whichever Python pre-commit ran under, so the cache kept handing back envs built on 3.12.14 and the hooks kept running there -- invisibly, right up to the first syntax 3.12 cannot parse. PEP 758 was that syntax. The previous commit's `except A, B:` reached pylint and the debug-statement hook on cached 3.12 interpreters and came back as "multiple exception types must be parenthesized", a failure with no local reproduction: developer caches were built on 3.14, where the same pylint 3.3.2 and the same pylint 4.0.7 both parse the file fine. The syntax was never the defect; the stale interpreter was. `steps.setup-python.outputs.python-version` cannot drift from what was installed, so this cannot recur on the next release either. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01SfnJmxxsZ534AKk16rC2Gr --- .github/workflows/pre-commit.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 74ec1dfa..f157ff55 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -29,6 +29,7 @@ jobs: path: .utils - uses: actions/setup-python@v5 + id: setup-python with: python-version: "3.x" # See the note in python-tests.yml: caches the pip download cache, @@ -127,10 +128,22 @@ jobs: # pre-commit builds a virtualenv per hook repo on first use, which is # slower than the pip install itself. Keyed on the hook definitions, so # it invalidates exactly when a hook's repo or rev changes. + # The interpreter goes in the key, resolved rather than typed. A + # `language: python` hook env is built by whichever Python pre-commit ran + # under, and restoring one built by a different release is silent: the + # hooks keep working right up to the first syntax the old interpreter + # cannot parse. This key said `py3.12` as a literal while the job had + # moved to `3.x`, so 3.14-only source (PEP 758's `except A, B:`) reached + # pylint and the debug-statement hook running on a cached 3.12.14 and + # came back as "multiple exception types must be parenthesized" -- a + # failure with no local reproduction, since developer caches were built + # on 3.14. `steps.setup-python.outputs.python-version` cannot drift from + # what was actually installed. - uses: actions/cache@v4 with: path: ~/.cache/pre-commit - key: pre-commit-${{ runner.os }}-py3.12-${{ hashFiles('.pre-commit-config.yaml') }} + key: >- + pre-commit-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }} - name: Install dependencies run: |