Skip to content

Accept positional/string context shorthand for Flow.model(context_type=)#237

Merged
timkpaine merged 1 commit into
nk/auto_deps_auto_callable_modelfrom
tkp/flow-model-context-shorthand
Jun 9, 2026
Merged

Accept positional/string context shorthand for Flow.model(context_type=)#237
timkpaine merged 1 commit into
nk/auto_deps_auto_callable_modelfrom
tkp/flow-model-context-shorthand

Conversation

@timkpaine

Copy link
Copy Markdown
Member

Class-based CallableModel execution already accepts positional/string context shorthand via ContextBase's ordered zip(model_fields, v) mapping (as used by Hydra +context=[...]). Generated @Flow.model instances expose the open FlowContext bag as their runtime context type, which has no declared fields to zip against, so positional shorthand was silently dropped.

When a generated model declares a context_type, compute() now validates non-mapping shorthand (list/tuple/str) through that declared type first, then forwards the named values into the FlowContext bag. Mapping and named-kwarg inputs keep their existing paths.

Scope: this covers the compute() entry point only. The direct-call form (model([...])) is intentionally not supported, since Flow.call validates against FlowContext before the generated body runs; supporting it would require reverting the bag-of-types design.

Adds _declared_context_type_for_model and focused tests for list/tuple/string shorthand, parity with named inputs, and that bag-only models are unaffected.

Class-based CallableModel execution already accepts positional/string context
shorthand via ContextBase's ordered `zip(model_fields, v)` mapping (as used by
Hydra `+context=[...]`). Generated @Flow.model instances expose the open
FlowContext bag as their runtime context type, which has no declared fields to
zip against, so positional shorthand was silently dropped.

When a generated model declares a `context_type`, `compute()` now validates
non-mapping shorthand (list/tuple/str) through that declared type first, then
forwards the named values into the FlowContext bag. Mapping and named-kwarg
inputs keep their existing paths.

Scope: this covers the `compute()` entry point only. The direct-call form
(`model([...])`) is intentionally not supported, since `Flow.call` validates
against FlowContext before the generated body runs; supporting it would require
reverting the bag-of-types design.

Adds `_declared_context_type_for_model` and focused tests for list/tuple/string
shorthand, parity with named inputs, and that bag-only models are unaffected.

Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
@timkpaine timkpaine force-pushed the tkp/flow-model-context-shorthand branch from d168556 to fae1c15 Compare June 9, 2026 22:49
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Test Results

    1 files  ±0      1 suites  ±0   2m 53s ⏱️ -1s
1 171 tests +7  1 169 ✅ +7  2 💤 ±0  0 ❌ ±0 
1 177 runs  +7  1 175 ✅ +7  2 💤 ±0  0 ❌ ±0 

Results for commit fae1c15. ± Comparison against base commit 51396bc.

♻️ This comment has been updated with latest results.

@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.02%. Comparing base (51396bc) to head (fae1c15).

Additional details and impacted files
@@                         Coverage Diff                          @@
##           nk/auto_deps_auto_callable_model     #237      +/-   ##
====================================================================
+ Coverage                             93.01%   93.02%   +0.01%     
====================================================================
  Files                                   160      161       +1     
  Lines                                 17835    17868      +33     
  Branches                               1153     1155       +2     
====================================================================
+ Hits                                  16589    16622      +33     
  Misses                                 1020     1020              
  Partials                                226      226              

☔ 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.

@timkpaine timkpaine merged commit d42b643 into nk/auto_deps_auto_callable_model Jun 9, 2026
20 checks passed
@timkpaine timkpaine deleted the tkp/flow-model-context-shorthand branch June 9, 2026 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant