Skip to content

Fix functools.partial() typehint breakage when using future annotations - #40747

Open
jrmccluskey wants to merge 2 commits into
apache:masterfrom
jrmccluskey:futureBug
Open

jrmccluskey wants to merge 2 commits into
apache:masterfrom
jrmccluskey:futureBug

Conversation

@jrmccluskey

Copy link
Copy Markdown
Contributor

Use of from future import __annotations__ created a case where type hint annotations passed through functools.partial() invocations failed. Future annotations convert all type hints to strings before processing, and when evaluated by the new type checking route introduced in #40625 the actual type was not getting resolved back to the underlying type, leaving the annotation as a string. This caused check failures, as the expected type in the type check code was being produced by IOHints.from_callable and resolved the string to the underlying type. This bug only impacts runtime environments that import from future import __annotations__ and Python 3.14+.

@github-actions github-actions Bot added python core size/s S: 10-49 lines changed labels Oct 23, 2026

@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 resolves string/forward-reference annotations for unbound parameters in getcallargs_forhints (such as keyword arguments pre-bound via functools.partial under from __future__ import annotations), matching the resolution performed in IOTypeHints.from_callable. However, getcallargs_forhints currently stops after _resolve_annotation without passing the result through convert_to_beam_type, which leaves a discrepancy with IOTypeHints.from_callable for unresolved forward references and types like TypedDict or Python 3.12 type aliases.

🔍 General Feedback

  • The lazy namespace lookup and _resolve_annotation integration in getcallargs_forhints cleanly mirror IOTypeHints.from_callable, and the regression test in typed_pipeline_test.py properly isolates and cleans up the dynamically created module.
  • Converting the resolved annotation via convert_to_beam_type in getcallargs_forhints will ensure full parity with IOTypeHints.from_callable.

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

Comment thread sdks/python/apache_beam/typehints/decorators.py Outdated
@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @claudevdm 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 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.94%. Comparing base (a8d6afd) to head (b034c74).
⚠️ Report is 70 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40747      +/-   ##
==========================================
- Coverage   80.04%   79.94%   -0.11%     
==========================================
  Files         490      493       +3     
  Lines       82916    83408     +492     
==========================================
+ Hits        66373    66678     +305     
- Misses      16543    16730     +187     
Flag Coverage Δ
python 79.94% <100.00%> (-0.11%) ⬇️

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.

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.

1 participant