Point72 / Point72/csp

typing.Any not handled properly as an output from a csp.node

Open
#436 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

lang: c++ type: bug type: enhancement
Dominant language
Python
Stars
441
Forks
90
Avg merge
1d 12m
Merged PRs (30d)
5

Description

Describe the bug
typing.Any is not handled properly. This occurs both if CSP_PYDANTIC is set as an environment behavior or not

To Reproduce

import csp
import typing

from datetime import datetime, timedelta

import sys

print(csp.__version__); print(sys.version); print(sys.platform)

@csp.node
def val(x: csp.ts[object]) -> csp.ts[typing.Any]:
    return x

@csp.node
def val2(x: csp.ts[typing.Any]) -> csp.ts[object]:
    return x

csp.run(val2, csp.const(1), starttime=datetime.utcnow(), endtime=timedelta(seconds=3))
csp.run(val, csp.const(1), starttime=datetime.utcnow(), endtime=timedelta(seconds=3))  # fails here

Expected behavior
Both of these should pass

Error Message

TypeError                                 Traceback (most recent call last)
Cell In[22], [line 20](vscode-notebook-cell:?execution_count=22&line=20)
     [17](vscode-notebook-cell:?execution_count=22&line=17)     return x
     [19](vscode-notebook-cell:?execution_count=22&line=19) csp.run(val2, csp.const(1), starttime=datetime.utcnow(), endtime=timedelta(seconds=3))
---> [20](vscode-notebook-cell:?execution_count=22&line=20) csp.run(val, csp.const(1), starttime=datetime.utcnow(), endtime=timedelta(seconds=3))  # fails here

File csp/csp/impl/wiring/runtime.py:167, in run(g, starttime, endtime, queue_wait_time, realtime, output_numpy, *args, **kwargs)
    [157](https://vscode-remote+ssh-002dremote-002bdev06.vscode-resource.vscode-cdn.netcsp/csp/impl/wiring/runtime.py:157) def run(
    [158](https://vscode-remote+ssh-002dremote-002bdev06.vscode-resource.vscode-cdn.netcsp/csp/impl/wiring/runtime.py:158)     g,
    [159](https://vscode-remote+ssh-002dremote-002bdev06.vscode-resource.vscode-cdn.net/csp/csp/impl/wiring/runtime.py:159)     *args,
   (...)
    [165](https://vscode-remote+ssh-002dremote-002bdev06.vscode-resource.vscode-cdn.net/csp/csp/impl/wiring/runtime.py:165)     **kwargs,
    [166](https://vscode-remote+ssh-002dremote-002bdev06.vscode-resource.vscode-cdn.net/csp/csp/impl/wiring/runtime.py:166) ):
--> [167](https://vscode-remote+ssh-002dremote-002bdev06.vscode-resource.vscode-cdn.net/csp/csp/impl/wiring/runtime.py:167)     with ExceptionContext():
    [168](https://vscode-remote+ssh-002dremote-002bdev06.vscode-resource.vscode-cdn.net/csp/csp/impl/wiring/runtime.py:168)         starttime, endtime = _normalize_run_times(starttime, endtime, realtime)
    [170](https://vscode-remote+ssh-002dremote-002bdev06.vscode-resource.vscode-cdn.net/csp/csp/impl/wiring/runtime.py:170)         engine_settings = {"queue_wait_time": queue_wait_time, "realtime": realtime, "output_numpy": output_numpy}

File csp/csp/impl/error_handling.py:40, in ExceptionContext.__exit__(self, exc_type, exc_val, exc_tb)
     [37](https://vscode-remote+ssh-002dremote-002bdev06.vscode-resource.vscode-cdn.net/csp/csp/impl/error_handling.py:37) if exc_type is CspParseError and exc_val.filename is not None and exc_val.lineno is not None:
     [38](https://vscode-remote+ssh-002dremote-002bdev06.vscode-resource.vscode-cdn.net/csp/csp/impl/error_handling.py:38)     new_tb = _cspimpl.create_traceback(new_tb, exc_val.frame, exc_val.lineno, exc_val.lineno)
---> [40](https://vscode-remote+ssh-002dremote-002bdev06.vscode-resource.vscode-cdn.net/csp/csp/impl/error_handling.py:40) raise exc_val.with_traceback(new_tb)

Cell In[22], [line 13](vscode-notebook-cell:?execution_count=22&line=13)
     [11](vscode-notebook-cell:?execution_count=22&line=11) @csp.node
     [12](vscode-notebook-cell:?execution_count=22&line=12) def val(x: csp.ts[object]) -> csp.ts[typing.Any]:
---> [13](vscode-notebook-cell:?execution_count=22&line=13)     return x

TypeError: PyOutputProxy.h:outputTick:56:TypeError: "val" node expected output type on output #0 to be of type "Any" got type "int"

Runtime Environment
0.0.7
3.12.7 | packaged by conda-forge | (main, Oct 4 2024, 16:05:46) [GCC 13.3.0]
linux

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

Reproduce the example on Python 3.12.7 with CSP 0.0.7, starting from csp/impl/wiring/runtime.py and the traceback through csp/impl/error_handling.py. Trace the output type validation for the val and val2 nodes, then verify that both csp.run calls complete without the reported TypeError.

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
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.