Skip to content

Ruff erroneously flagging modern syntax as syntax errors due to targeting Python 3.12 #144639

Activity

  1. BasavarajBankolli commented on Feb 10, 2026

    @BasavarajBankolli

    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.

  2. added
    infraCI, GitHub Actions, buildbots, Dependabot, etc.
    on Feb 10, 2026
  3. hugovk commented on Feb 10, 2026

    @hugovk
    Member

    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 to py313, but that won't help here.

  4. AlexWaygood commented on Feb 10, 2026

    @AlexWaygood
    Member

    @AlexWaygood Remind me of the reason for target-version = "py312"? Is it to ease backporting? In which case we could at least bump to py313, 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:

    target-version = "py310"
    . I haven't dug through the blame to see if I can figure out why it was originally set to py312, but off the top of my head, I think bumping the target version in Lib/test/.ruff.toml to py314 should 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.

  5. hugovk commented on Feb 10, 2026

    @hugovk
    Member

    I haven't dug through the blame to see if I can figure out why it was originally set to py312

    It 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.toml to py314 should be fine at this point!

    Please see #144656.

  6. added a commit that references this issue on Feb 11, 2026
  7. added 2 commits that reference this issue on Feb 11, 2026
  8. added a commit that references this issue on Feb 15, 2026
  9. added a commit that references this issue on Feb 28, 2026
  10. added a commit that references this issue on Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    infraCI, GitHub Actions, buildbots, Dependabot, etc.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions