Skip to content

We should allow specifying adjusted input annotations before csp.start / csp.alarms / csp.state #664

Description

@robambalu

Given csp's ts[] duality in csp.node its convenient to annotate inputs as their non-ts types within the node for better IDE support.
CSP wont allow these annotations before csp.start/alarms/state blocks because csp enforces that these blocks be at the start of the method. We can / should relax this constraint to allow bare annotation lines to be declared though, since its more natural to list these up front next to the function signature

Example

import csp

@csp.node
def foo(x:csp.ts[int]):
    x : int
    with csp.start():
        s_foo = None

Leads to

Traceback (most recent call last):
  File "/home/ra7293/.config/JetBrains/PyCharm2025.2/scratches/scratch_27.py", line 3, in <module>
    @csp.node
     ^^^^^^^^
  File "/home/ra7293/user/github/csp/csp/impl/wiring/node.py", line 280, in node
    with ExceptionContext():
         ^^^^^^^^^^^^^^^^^^
  File "/home/ra7293/user/github/csp/csp/impl/error_handling.py", line 44, in __exit__
    raise exc_val.with_traceback(new_tb)
  File "/home/ra7293/.config/JetBrains/PyCharm2025.2/scratches/scratch_27.py", line 4, in <module>
    def foo(x:csp.ts[int]):
    ^^^^^^^^^^
  File "/home/ra7293/.config/JetBrains/PyCharm2025.2/scratches/scratch_27.py", line 4, in <module>
    def foo(x:csp.ts[int]):
    ^^^^^^^^^^
  File "/home/ra7293/.config/JetBrains/PyCharm2025.2/scratches/scratch_27.py", line 4, in <module>
    def foo(x:csp.ts[int]):
    ^^^^^^^^^^
csp.impl.wiring.base_parser.CspParseError: Invalid usage of start, it should appear at the beginning of the function (consult documentation for details)

Activity

  1. added
    type: featureIssues and PRs related to new features
    type: enhancementIssues and PRs related to improvements to existing features
    and removed
    type: featureIssues and PRs related to new features
    on Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: enhancementIssues and PRs related to improvements to existing features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions