Skip to content

Allow None output annotations for graphs/nodes without outputs #625

@AdamGlustein

Description

@AdamGlustein

Describe the bug

If you annotate a graph or node with an output of None (i.e. it has no output), the graph fails to build.

To Reproduce

import csp
from datetime import datetime

@csp.node
def n(x: csp.ts[int]) -> None:
    print(x)

@csp.graph
def g() -> None:
    n(csp.const(1))

csp.run(g, datetime(2020, 1, 1))

gives:

  File "ex.py", line 5, in <module>
    def n(x: csp.ts[int]) -> None:
    ^^^^^^^^^^
csp.impl.wiring.base_parser.CspParseError: outputs must be ts[] or basket types, got None

If you remove the node annotation and instead do:

import csp
from datetime import datetime

@csp.node
def n(x: csp.ts[int]):
    print(x)

@csp.graph
def g() -> None:
    n(csp.const(1))

csp.run(g, datetime(2020, 1, 1))

you get the analogous error for the graph:

  File "/data01/home/ag11460/user/hfalgotr/ex.py", line 9, in <module>
    def g() -> None:
    ^^^^^^^^^^
csp.impl.wiring.base_parser.CspParseError: outputs must be ts[] or basket types, got None

Expected behavior

we should properly parse a None return type

Error Message

Runtime Environment

0.12.0
3.11.11 (main, Jan 30 2025, 14:30:53) [GCC 13.3.0]
linux

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang: pythonIssues and PRs related to the Python codebasetype: bugConcrete, reproducible bugs

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions