Skip to content

Python: Add extractor support for Python 3.15 - #22728

Merged
tausbn merged 6 commits into
mainfrom
tausbn/python-extractor-support-python-3.15
Oct 2, 2026
Merged

tausbn merged 6 commits into
mainfrom
tausbn/python-extractor-support-python-3.15

Conversation

@tausbn

@tausbn tausbn commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

In addition to the previous work, two more minor changes were needed:

  • match patterns can now start with unary plus (e.g. case +5: ...).
  • Identifier start and continuation characters now follow Unicode 17 (which slightly expands these classes).

Both of these are fixed in the current PR. I suggest reviewing commit-by-commit (and skipping the second and fourth commits, as they only regenerate parser files).

tausbn and others added 5 commits October 1, 2026 15:31
Constructs such as
```python
match x:
    case +5:
        pass
```
are now allowed in Python 3.15 (just as `case -5` would have
previously). To support this new syntax, we need to extend the
tree-sitter based parser slightly.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Supplement the generator's Unicode 16 identifier properties with the exact Unicode 17 additions, independently of the extraction host's Python version.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tausbn
tausbn marked this pull request as ready for review October 1, 2026 15:55
@tausbn
tausbn requested review from a team as code owners October 1, 2026 15:55
Copilot AI balanced review requested due to automatic review settings October 1, 2026 15:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The synthesized unary-plus nodes omit the operator from their source locations because the location override uses an unrecognized attribute name.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds Python 3.15 extraction support for unary-plus match patterns and Unicode 17 identifiers.

Changes:

  • Extends tree-sitter grammar and lowering.
  • Adds parser and extraction coverage.
  • Updates extractor version and documentation.
File Description
python/​ql/​test/​3/​extractor-tests/​unicode17-identifiers/​test.ql Queries extracted identifiers.
python/​ql/​test/​3/​extractor-tests/​unicode17-identifiers/​test.py Adds Unicode 17 examples.
python/​ql/​test/​3/​extractor-tests/​unicode17-identifiers/​test.expected Records query results.
python/​ql/​test/​3/​extractor-tests/​match-unary-plus/​test.ql Queries unary expressions.
python/​ql/​test/​3/​extractor-tests/​match-unary-plus/​test.py Exercises unary-plus patterns.
python/​ql/​test/​3/​extractor-tests/​match-unary-plus/​test.expected Records unary-expression results.
python/​ql/​lib/​change-notes/​2026-09-22-python315-extractor.md Documents Python 3.15 support.
python/​extractor/​tsg-python/​tsp/​src/​node-types.json Updates generated node metadata.
python/​extractor/​tsg-python/​tsp/​src/​grammar.json Updates generated grammar metadata.
python/​extractor/​tsg-python/​tsp/​grammar.js Adds grammar support for both features.
python/​extractor/​tsg-python/​python.tsg Lowers unary plus to UAdd.
python/​extractor/​tests/​parser/​unicode_identifiers_new.py Adds parser fixture.
python/​extractor/​tests/​parser/​unicode_identifiers_new.expected Records Unicode parser AST.
python/​extractor/​tests/​parser/​match_new.py Expands match parser coverage.
python/​extractor/​tests/​parser/​match_new.expected Records match parser AST.
python/​extractor/​semmle/​util.py Bumps extractor version to 7.2.0.
python/​extractor/​extending-the-parser.md Updates regeneration guidance.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread python/extractor/tsg-python/python.tsg
Somehow, in the original implementation of support for `match`, we had
used `_start_location` instead of `_location_start`, which meant we
didn't override the location after all.

This was the only occurrence of this mistake in `python.tsg`.

@andersfugmann andersfugmann left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Copilot does have a relevant comment. Could you comment on that?

@tausbn

tausbn commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Copilot does have a relevant comment. Could you comment on that?

That's fixed in fa4ce46.
(I thought it would have been marked as resolved automatically, but I guess the actual change was outside of the part of the diff the comment is attached to.)

@andersfugmann

Copy link
Copy Markdown
Contributor

Thanks. I also saw it as fixed so I was slightly confused about the comment. Thanks for resolving.

@andersfugmann andersfugmann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@tausbn
tausbn merged commit 072e00d into main Oct 2, 2026
17 checks passed
@tausbn
tausbn deleted the tausbn/python-extractor-support-python-3.15 branch October 2, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants