Repository navigation
Fix functools.partial() typehint breakage when using future annotations - #40747
jrmccluskey wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
📋 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_annotationintegration ingetcallargs_forhintscleanly mirrorIOTypeHints.from_callable, and the regression test intyped_pipeline_test.pyproperly isolates and cleans up the dynamically created module. - Converting the resolved annotation via
convert_to_beam_typeingetcallargs_forhintswill ensure full parity withIOTypeHints.from_callable.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @claudevdm for label python. 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 Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Use of
from future import __annotations__created a case where type hint annotations passed throughfunctools.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 importfrom future import __annotations__and Python 3.14+.