-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
The input node value field is typed to be literally anything, but my abstract understanding is that it ought to be some sort of "primitive" data. Concretely, the current implementation does not have the juice to support the arbitrary type:
import numpy as np
from python_workflow_definition import models
inp_model = models.PythonWorkflowDefinitionInputNode.model_validate(
{
"id": 0,
"type": "input",
"name": "x",
# "value": 1, # Case 1
# "value": (1, 2), # Case 2
# "value": np.arange(5) # Case 3
}
)
print(inp_model.model_dump_json(indent=2))
def cycle(model: models.PythonWorkflowDefinitionInputNode) -> bool:
reloaded = type(model).model_validate(
model.model_dump(mode="json"),
)
return model == reloaded
cycle(inp_model)- Case 1: Totally fine
- Case 2: Dumps to something pretty reasonable, but doesn't cycle
- Case 3: Won't validate because the data is not serializable
Is the typing here simply too permissive, or have I misunderstood the intent? If the latter, is there some plan for how to technically support non-primitive data?
TBH, I'm not exactly sure what I mean by primitive, but I guess something in this direction:
from typing import Union
JsonPrimitive = Union[str, int, float, bool, None]
JsonValue = Union[JsonPrimitive, list["JsonValue"], dict[str, "JsonValue"]]Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels