Casting of ts[int] to ts[float] as part of type checking will mutate input baskets in-place, which can lead to downstream errors.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 441
- Forks
- 90
- Avg merge
- 1d 12m
- Merged PRs (30d)
- 5
Description
Describe the bug
csp mutates dict/list baskets of ints when casting to float (instead of making a copy when casting is needed). This can cause errors in downstream code.
To Reproduce
@csp.graph
def foo(x: Dict[str, ts[float]], y: List[ts[float]]) -> ts[bool]:
return csp.const(True)
x = {"a": csp.const(1)}
y = [csp.const(1)]
z = foo(x, y)
# At this stage, both x and y will have been replaced by ts[float], which is not what downstream code might expect, i.e.
try:
csp.cast_int_to_float(x["a"])
except TypeError:
print("This should not happen")
try:
csp.cast_int_to_float(y[0])
except TypeError:
print("This should not happen either")
Expected behavior
The input baskets should be left as-is, and the type checking/casting code should make it's own copy of the basket to mutate
Error Message
Runtime Environment
0.0.2
3.11.7 | packaged by conda-forge | (main, Dec 23 2023, 14:43:09) [GCC 12.3.0]
linux
Additional context
A functional language should not mutate its input arguments
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
No source file or test is identified. Start by running the Python reproduction with the foo graph and trace the type-checking path that casts nested dict/list baskets; done means x and y retain their original ts[int] values while the cast proceeds on its own basket copy.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- stream-processing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100