Repository navigation
Ruff erroneously flagging modern syntax as syntax errors due to targeting Python 3.12 #144639
Description
Activity
The reported syntax error appears to be a false positive.
The code uses except (FileNotFoundError, NotImplementedError):, which is valid Python 3.12 syntax.
This looks like a Ruff parser issue or an unintended lint of CPython Lib/test/support files.
Excluding Lib/test/** from E999 or upgrading Ruff should resolve this.- addedinfraCI, GitHub Actions, buildbots, Dependabot, etc.CI, GitHub Actions, buildbots, Dependabot, etc.
on Feb 10, 2026 Because GH logs eventually expire, the error is:
Run Ruff (lint) on Lib/test/.............................................Failed - hook id: ruff-check - exit code: 1 Error: Lib/test/support/import_helper.py:74:12: invalid-syntax: Multiple exception types must be parenthesized on Python 3.12 (syntax was added in Python 3.14)Caused by:
- except (FileNotFoundError, NotImplementedError): + except FileNotFoundError, NotImplementedError:
We're already on the latest Ruff. Excluding E999 won't help, it's failing to parse the 3.14 syntax because it expects 3.12.
Here's one fix:
diff --git a/Lib/test/.ruff.toml b/Lib/test/.ruff.toml index a1b749798fa..c9ffc869375 100644 --- a/Lib/test/.ruff.toml +++ b/Lib/test/.ruff.toml @@ -16,6 +16,9 @@ extend-exclude = [ ] [per-file-target-version] +# Multiple exception types are unparenthesized +"support/import_helper.py" = "py314" + # Type parameter defaults "test_type_params.py" = "py313"
@AlexWaygood Remind me of the reason for
target-version = "py312"? Is it to ease backporting? In which case we could at least bump topy313, but that won't help here.@AlexWaygood Remind me of the reason for
target-version = "py312"? Is it to ease backporting? In which case we could at least bump topy313, but that won't help here.I think the important thing is that this value needs to be set to the same as
PYTHON_FOR_REGEN(which it is), so that our scripts in the Tools/ directory don't start accidentally using newer syntax than they're meant to:. I haven't dug through the blame to see if I can figure out why it was originally set toLine 4 in d2d2459
target-version = "py310" py312, but off the top of my head, I think bumping the target version inLib/test/.ruff.tomltopy314should be fine at this point! It might be that the reason it needs to be explicitly specified there is because we need to override the target version in the global config.Reacted by Hugo van KemenadeI haven't dug through the blame to see if I can figure out why it was originally set to
py312It was done in #137591 because a Ruff upgrade started giving "invalid-syntax: Cannot use type alias statement on Python 3.10 (syntax was added in Python 3.12)".
but off the top of my head, I think bumping the target version in
Lib/test/.ruff.tomltopy314should be fine at this point!Please see #144656.
https://github.com/python/cpython/actions/runs/21837777864/job/63013625923?pr=144293 is an example.
Linked PRs
Lib/test#144656Lib/test(GH-144656) #144710