Skip to content

csp.output does not support dict unpacking #725

Description

@AdamGlustein

Is your feature request related to a problem? Please describe.

Using csp.output to return named outputs from a node does not support dict unpacking when passing arguments. We fail when parsing the AST.

Example repro:

import csp
from datetime import datetime, timedelta

@csp.node
def reproduce(trigger: csp.ts[bool]) -> csp.Outputs(
    a=csp.ts[int],
    b=csp.ts[int],
):
    if csp.ticked(trigger):
        values = {"a": 1, "b": 2}
        csp.output(**values)

        # This explicit equivalent parses successfully:
        # csp.output(a=1, b=2)

@csp.graph
def graph():
    result = reproduce(csp.const(True))
    csp.print("a", result.a)
    csp.print("b", result.b)


if __name__ == "__main__":
    csp.run(
        graph,
        starttime=datetime(2026, 1, 1),
        endtime=timedelta(seconds=1),
    )

fails with

  File "/tmp/csp_output_kwargs_github_repro.py", line 11, in <module>
    csp.output(**values)
^^^^^^^^^^^^^^^^^^^^^^^^^
csp.impl.wiring.base_parser.CspParseError: unrecognized output 'None'

Describe the solution you'd like
It would be nice if we supported standard dict unpacking in the AST logic as it can often simplify nodes with many return values (no need to write explicitly every field). For example:

csp.output(**{f: values[f] for f in FIELDS})
vs

csp.output(
    field1=values['field1'],
    ...,
    fieldN=values['fieldN'],

Describe alternatives you've considered
We could also just support parsing the dict as an allowable return value as well i.e. csp.output(values) where values is a dict. This is currently unsupported as well, fails with

  File "/tmp/csp_output_kwargs_github_repro.py", line 11, in <module>
    csp.output(values)
^^^^^^^^^^^^^^^^^^^^^^^
csp.impl.wiring.base_parser.CspParseError: cannot csp.output single unnamed arg in node returning 2 outputs

Additional context
n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: featureIssues and PRs related to new features

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions