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) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SfnJmxxsZ534AKk16rC2Gr
This commit is contained in:
Krzysztof Rudnicki 2026-08-29 12:01:52 +02:00
parent 7decc499cb
commit 6eb70de0ba

View File

@ -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: |