Fix Optional[FromContext[T]] classification and define its semantics#235
Merged
timkpaine merged 2 commits intoJun 9, 2026
Merged
Conversation
`_parse_annotation` only peeled the top-level `Annotated`, so `Optional[FromContext[int]]` (a Union on the outside) was silently misclassified as a regular parameter and every call failed with a misleading "cannot satisfy unbound regular parameter" error. Detect `FromContext`/`Lazy` markers nested inside a top-level Optional and define the two spellings precisely: - `FromContext[Optional[int]]`: contextual, required-in-context, value may be None. - `Optional[FromContext[int]]`: contextual, optional; absent -> bound to None (an implicit None default synthesized in `_analyze_flow_function`). `FromContext[Optional[int]] = None` is therefore equivalent to `Optional[FromContext[int]]`, and an explicit default still wins. Distinct required-ness yields distinct config/cache identities via the existing has_function_default/function_default identity terms. Reject nested `Lazy` (`Optional[Lazy[int]]`) and non-Optional unions carrying `FromContext` (e.g. `Union[FromContext[int], str]`) with clear messages. Adds focused regression tests covering all call shapes, the consistency equivalences, and the rejection cases. Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
Contributor
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## nk/auto_deps_auto_callable_model #235 +/- ##
===================================================================
Coverage ? 93.01%
===================================================================
Files ? 160
Lines ? 17835
Branches ? 1153
===================================================================
Hits ? 16589
Misses ? 1020
Partials ? 226 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ptional-fromcontext
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_parse_annotationonly peeled the top-levelAnnotated, soOptional[FromContext[int]](a Union on the outside) was silently misclassified as a regular parameter and every call failed with a misleading "cannot satisfy unbound regular parameter" error.Detect
FromContext/Lazymarkers nested inside a top-level Optional and define the two spellings precisely:FromContext[Optional[int]]: contextual, required-in-context, value may be None.Optional[FromContext[int]]: contextual, optional; absent -> bound to None (an implicit None default synthesized in_analyze_flow_function).FromContext[Optional[int]] = Noneis therefore equivalent toOptional[FromContext[int]], and an explicit default still wins. Distinct required-ness yields distinct config/cache identities via the existing has_function_default/function_default identity terms.Reject nested
Lazy(Optional[Lazy[int]]) and non-Optional unions carryingFromContext(e.g.Union[FromContext[int], str]) with clear messages.Adds focused regression tests covering all call shapes, the consistency equivalences, and the rejection cases.