Skip to content

[Python] Convert typing and native generic hints in Watch coder inference - #39547

Merged
Abacn merged 1 commit into
apache:masterfrom
Eliaaazzz:python-watch-coder-inference
Jul 29, 2026
Merged

[Python] Convert typing and native generic hints in Watch coder inference#39547
Abacn merged 1 commit into
apache:masterfrom
Eliaaazzz:python-watch-coder-inference

Conversation

@Eliaaazzz

Copy link
Copy Markdown
Contributor

coders.registry.get_coder receives typing and native generic annotations unconverted: typing.Tuple[str, float] and tuple[str, float] both fall back to FastPrimitivesCoder (pickling) instead of a real TupleCoder. Watch infers its output coder and its dedup-key coder from return annotations, so an annotated poll function or key function silently got a pickling coder and the (input, output) element type degraded to Any.

Watch now converts the hint with native_type_compatibility.convert_to_beam_type before the registry lookup, at both inference sites. A poll function annotated -> PollResult[tuple[str, float]] yields a real tuple coder and a fully typed element type; the same applies to output_key_fn return annotations, which #39461 relies on for MatchContinuously's (path, mtime) dedup keys.

Split out of #39461 per review so the inference fix can land on its own.

Tests: a new watch_test case covers the native and typing.Tuple annotation forms end to end through expand. 28 watch tests pass; yapf and ruff clean.


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

  • Choose reviewer(s) and mention them in a comment (R: @username).
  • 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

…ence

registry.get_coder receives typing and native generic annotations such
as tuple[str, float] unconverted and falls back to pickling. Watch now
converts hints with convert_to_beam_type before the registry lookup, so
annotated poll functions and key functions infer real structured coders
and fully typed elements.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@Eliaaazzz

Copy link
Copy Markdown
Contributor Author

R: @Abacn

Eliaaazzz added a commit to Eliaaazzz/beam that referenced this pull request Jul 29, 2026
watch.py and watch_test.py return to master; the inference fix lands
separately so it can make the release cut. The annotated key functions
meanwhile fall back to the deterministic FastPrimitivesCoder form, which
keeps dedup correct.
@github-actions

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@Abacn Abacn 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!

Verified that the newly added unit test fails on HEAD and passed with this change

@Abacn
Abacn merged commit 8a1c19b into apache:master Jul 29, 2026
99 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