Skip to content

Python: trailing comma in a PEP 695 type parameter list causes a parse error #22739

Description

@jopemachine

Description of the issue

The Python extractor (CodeQL CLI 2.27.1) fails to parse a trailing comma after the last type parameter, and the file is dropped from analysis. This applies to class, def and type statements. ruff format and Black add this comma whenever they split a long type parameter list, so formatted code runs into it.

class A[
    T: int,
    U: str,  # Syntax Error here
]:
    pass

type_parameters in tsg-python/tsp/grammar.js has no optional trailing comma, while CPython's grammar does (type_param_seq: ','.type_param+ [',']). Adding it fixes the error:

     type_parameters: $ => seq(
       '[',
       commaSep1(field('type_parameter', $._type_parameter)),
+      optional(','),
       ']'
     ),

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions