Point72 / Point72/csp

csp.output does not support dict unpacking

Open
#725 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: feature
Dominant language
Python
Stars
441
Forks
90
Avg merge
1d 12m
Merged PRs (30d)
5

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided Python reproduction and tracing the AST handling for csp.output, especially the path that raises csp.impl.wiring.base_parser.CspParseError. Compare dict-unpacked arguments with explicit keyword arguments. Done means csp.output(**values) works for named outputs and regression coverage verifies the reported example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
stream-processing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.