Skip to content

[#28420] Fix type inference for closures over local variables#39210

Open
lakshitbahl wants to merge 1 commit into
apache:masterfrom
lakshitbahl:fix-28420-closure-type-inference
Open

[#28420] Fix type inference for closures over local variables#39210
lakshitbahl wants to merge 1 commit into
apache:masterfrom
lakshitbahl:fix-28420-closure-type-inference

Conversation

@lakshitbahl

@lakshitbahl lakshitbahl commented Jul 3, 2026

Copy link
Copy Markdown

###Description:
This PR resolves closure-related type inference regressions (see #28420) and restores compatibility with Python 3.11+ opcode changes. It introduces two distinct fixes under a unified closure-handling improvement, allowing us to un-skip testLocalClosure.

  1. Type-vs-Value Cell Confusion
    Prevents the inference engine from confusing synthetic inferred types with real runtime closure values. Introduces the _TypeInCell marker class to safely wrap, track, and unwrap inferred types within the frame emulation, ensuring strict isolation from actual Python cell contents.

  2. Python 3.11+ Shared-Slot Indexing
    Fixes LOAD_CLOSURE and LOAD_DEREF indexing for Python 3.11 and newer. Replaces the legacy arg -= len(co_varnames) arithmetic, which broke when captured parameters shared a slot in the new unified localsplus array with version-aware slot-name resolution. This correctly maps variables and prevents out-of-bounds IndexError exceptions that were previously being swallowed by the safe-mode execution and degraded to Any.


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@github-actions github-actions Bot added the python label Jul 3, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the summary. You can try again by commenting /gemini summary.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant