Push adapter initialization does not forward annotation arguments correctly
Push adapters (potentially all adapters, haven't checked) are normalizing annotation arguments even if they are not within a csp.ts object.
Describe the bug
To Reproduce
from datetime import datetime, timedelta
from typing import Dict, TypeVar
import csp
from csp.impl.pushadapter import PushInputAdapter
from csp.impl.wiring import py_push_adapter_def
T = TypeVar("T")
class _AdapterImpl(PushInputAdapter):
def __init__(self, ts_typ: T): # noqa
print(ts_typ)
raise
def start(self, starttime: datetime, endtime: datetime):
pass
def stop(self):
pass
MyPushAdapter = py_push_adapter_def(
"adapter_def",
_AdapterImpl,
csp.ts[T],
ts_typ=T,
)
@csp.graph
def my_graph() -> csp.ts[Dict[str, int]]:
data = MyPushAdapter(ts_typ=Dict[str,int])
return data
csp.run(my_graph, starttime=datetime.utcnow(), endtime=timedelta())
Prints: class <dict> instead of typing.Dict[str, int]
Expected behavior
Should print typing.Dict[str, int]
Error Message
Runtime Environment
0.11.1
3.11.11 (main, Jan 30 2025, 14:30:53) [GCC 13.3.0]
linux
Additional context
This is somewhat by design since csp normalizes all typing types to basic python types for type mapping at the c++ level when passing type info to c++ adapters. The same mechanism is used regardless of the adapter impl ( python or c++ ) What practical issue is this causing?
This is somewhat by design since csp normalizes all typing types to basic python types for type mapping at the c++ level when passing type info to c++ adapters. The same mechanism is used regardless of the adapter impl ( python or c++ ) What practical issue is this causing?
The variable ts_typ here is just a regular argument to the __init__ function so it shouldn't be normalized, that is the problem.
@arhamchopra is trying to write an adapter for polling files to output dictionaries of structs and ran into this.
Again the problem is that the same code is used to pass type info to c++ ( this is used by output adapters regularly ) I think now that typing is much more mature than when we started maybe the best thing to do is actually stop normalizing all together and passing typing constructs down to c++ instead