Skip to content

Support **dict expansion at resolved method call sites#676

Merged
shigoel merged 12 commits intomainfrom
feat/dict-expand-call-site
Mar 26, 2026
Merged

Support **dict expansion at resolved method call sites#676
shigoel merged 12 commits intomainfrom
feat/dict-expand-call-site

Conversation

@MikaelMayer
Copy link
Copy Markdown
Contributor

Support **dict expansion at resolved method call sites

Python code often builds a parameter dictionary and passes it to a method
call using **, e.g. client.start_job_run(**params). When the target
method had a known signature (via pyspec), the translator would fail with
'method' called with unknown keyword arguments: [] because it couldn't
match the unnamed ** keyword to individual named parameters.

This PR detects **dict at call sites of resolved methods and expands the
dictionary into individual arguments: required parameters use
DictStrAny_get (preserving the precondition that the key must exist), and
optional parameters use a new prelude function DictStrAny_get_or_none
(returns None if the key is absent).

Two end-to-end tests were added to the dispatch test suite: one covering
all-required parameters, one covering a mix of required and optional
parameters where the dictionary omits the optional keys. All existing tests
continue to pass.

Python code often builds a parameter dictionary and passes it to a method
call using **, e.g. client.start_job_run(**params). When the target method
had a known signature (via pyspec), the translator would fail with
'method called with unknown keyword arguments: []'.

Detect **dict at call sites of resolved methods and expand the dictionary
into individual arguments: required params use DictStrAny_get, optional
params use a new prelude function DictStrAny_get_or_none.
Address review comment: DictStrAny_get_param with isOptional=false
produces the same call, so the standalone helper is dead code.

The transparent procedure handling for **dict expansion mirrors the
existing non-**dict path (returns .Hole for opt_firstarg). Fixing this
for both paths requires separate investigation.
@MikaelMayer

This comment was marked as resolved.

Address review: the **dict path now handles transparent procedures
(pyspec with precondition assertions) the same way as the named-kwargs
path. This required switching from DictStrAny_get to Any_get/Any_get_or_none
which operate on Any-typed variables.

Added Any_get_or_none to the prelude: extracts a dict value by key,
returning None if the key is absent.
MikaelMayer

This comment was marked as outdated.

Deduplicate the Name/Attribute dispatch logic between the **dict
expansion path and the named-kwargs path.
@MikaelMayer MikaelMayer marked this pull request as ready for review March 26, 2026 18:48
@MikaelMayer MikaelMayer requested a review from a team March 26, 2026 18:48
@MikaelMayer MikaelMayer enabled auto-merge March 26, 2026 18:49
shigoel
shigoel previously approved these changes Mar 26, 2026
joscoh
joscoh previously approved these changes Mar 26, 2026
@MikaelMayer MikaelMayer added this pull request to the merge queue Mar 26, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Mar 26, 2026
@MikaelMayer MikaelMayer dismissed stale reviews from joscoh and shigoel via 475e865 March 26, 2026 19:53
@shigoel shigoel added this pull request to the merge queue Mar 26, 2026
Merged via the queue into main with commit 04aa744 Mar 26, 2026
15 checks passed
@shigoel shigoel deleted the feat/dict-expand-call-site branch March 26, 2026 20:32
olivier-aws pushed a commit that referenced this pull request Mar 30, 2026
Support `**dict` expansion at resolved method call sites

Python code often builds a parameter dictionary and passes it to a
method
call using `**`, e.g. `client.start_job_run(**params)`. When the target
method had a known signature (via pyspec), the translator would fail
with
`'method' called with unknown keyword arguments: []` because it couldn't
match the unnamed `**` keyword to individual named parameters.

This PR detects `**dict` at call sites of resolved methods and expands
the
dictionary into individual arguments: required parameters use
`DictStrAny_get` (preserving the precondition that the key must exist),
and
optional parameters use a new prelude function `DictStrAny_get_or_none`
(returns `None` if the key is absent).

Two end-to-end tests were added to the dispatch test suite: one covering
all-required parameters, one covering a mix of required and optional
parameters where the dictionary omits the optional keys. All existing
tests
continue to pass.
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.

3 participants