GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-161808: Raise SyntaxError for unsupported ElementPath tokens by qventymr · Pull Request #161810 · python/cpython

Conversation

@qventymr

@qventymr qventymr commented Nov 11, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Fixes #161808.

ElementPath currently leaks a KeyError when a path contains a token that cannot
start a supported XPath step, such as @, =, or ). Check the token's handler
before calling it and raise SyntaxError("invalid path") when none exists.

Keep the C accelerator's literal tag fast path unchanged. This addresses the
exception leak described in the issue without changing which paths the
accelerator delegates to ElementPath.

The regression test covers find(), findall(), findtext(), and iterfind()
on both Element and ElementTree objects. The shared test suite runs it with
both the Python implementation and the C accelerator. Paths starting with
./ ensure that the accelerator also delegates these cases to ElementPath.

Validation on a locally built Windows x64 debug CPython 3.16.0a2+dev:

  • Before the fix, the new test fails in all 176 subtests across both implementations.
  • After the fix, the new test passes in both implementations.
  • PCbuild\amd64\python_d.exe -m test test_xml_etree test_xml_etree_c
    succeeds: 539 tests, 13 skipped.

AI assistance (Codex) was used to investigate the issue and prepare the patch
and regression test.

  • Issue: ElementTree: invalid paths raise KeyError instead of SyntaxError, and C and Python disagree on them #161808

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@qventymr
pythongh-161808: Raise SyntaxError for unsupported ElementPath tokens
ddd0576
@python-cla-bot

python-cla-bot Bot commented Nov 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot mentioned this pull request Nov 11, 2026
ElementTree: invalid paths raise KeyError instead of SyntaxError, and C and Python disagree on them #161808
Open
@bedevere-app bedevere-app Bot added the awaiting review label Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

ElementTree: invalid paths raise KeyError instead of SyntaxError, and C and Python disagree on them

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@qventymr
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.