Skip to content

Update Trivial Inference for Python 3.15 - #40578

Merged
jrmccluskey merged 1 commit into
apache:masterfrom
jrmccluskey:anotherTrivialPursuit
Oct 15, 2026
Merged

jrmccluskey merged 1 commit into
apache:masterfrom
jrmccluskey:anotherTrivialPursuit

Conversation

@jrmccluskey

Copy link
Copy Markdown
Contributor

Updates the trivial inference state machine for Python 3.15 opcodes. Tested locally; will not be exercised on-repo until 3.15 support is added outright.

Part of #40249

@github-actions github-actions Bot 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.

📋 Review Summary

This PR updates the bytecode-based trivial type inference state machine (opcodes.py and trivial_inference.py) to accommodate Python 3.15 bytecode changes. It properly handles the new two-slot iterator stack representation (GET_ITER, FOR_ITER, POP_ITER, END_SEND), the expanded LOAD_COMMON_CONSTANT opcode, and generator expression call patterns where GET_ITER moved inside the generator code object.

🔍 General Feedback

  • The changes are well-isolated with sys.version_info checks, ensuring full backwards compatibility with existing Python versions.
  • Stack-relative adjustments and constant table lookups are handled cleanly with clear inline documentation explaining the CPython 3.15 runtime mechanics.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @damccorm for label python.
Backup reviewer: shunping (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

This pull request likely touches a core component ("core" label). Please review with scrutiny.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@codecov

codecov Bot commented Oct 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 35.00000% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.92%. Comparing base (76f6e6d) to head (2319e42).
⚠️ Report is 164 commits behind head on master.

Files with missing lines Patch % Lines
sdks/python/apache_beam/typehints/opcodes.py 27.27% 8 Missing ⚠️
.../python/apache_beam/typehints/trivial_inference.py 44.44% 5 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             master   #40578       +/-   ##
=============================================
+ Coverage     56.16%   79.92%   +23.75%     
=============================================
  Files          1124      488      -636     
  Lines        178336    82362    -95974     
  Branches       1489        0     -1489     
=============================================
- Hits         100170    65831    -34339     
+ Misses        75645    16531    -59114     
+ Partials       2521        0     -2521     
Flag Coverage Δ
go ?
java ?
python 79.92% <35.00%> (+0.37%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@damccorm damccorm 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.

Generally LGTM, but had one question

state.stack.append(Const(arg))


def load_common_constant(state, arg):

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.

Is this called anywhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It doesn't have a direct call but will be used when the typehint tests run on 3.15. The functions defined in opcodes.py get imported in infer_return_type_func() and placed into a dictionary, then invoked through that dict entry rather than calling the function directly. This is the general convention for any operation that doesn't do more complex behavior like modifying the program counter

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.

Got it, thanks

@jrmccluskey
jrmccluskey merged commit 84b6221 into apache:master Oct 15, 2026
107 of 109 checks passed
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.

2 participants