We should allow specifying adjusted input annotations before csp.start / csp.alarms / csp.state
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 441
- Forks
- 90
- Avg merge
- 1d 12m
- Merged PRs (30d)
- 5
Description
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)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The traceback points to csp/impl/wiring/node.py and csp/impl/wiring/base_parser.py; start by tracing how csp.node parses statements before csp.start, csp.alarms, and csp.state. Confirm the relevant parser tests or add coverage for the shown x: int example, with bare annotations accepted before these blocks while other ordering rules remain enforced.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- stream-processing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100