Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ccflow/callable.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,11 @@ def _validate_callable_model_generic_type(cls, m, handler, info):
m = resolve_str(m)
if isinstance(m, dict):
m = handler(m)
if handler.__class__.__name__.lower().startswith("assignmentvalidator"):
# NOTE: this is a relatively nuanced problem, where we want to validate
# assignment but not generic validation. Unfortunately these classes
# are not exposed from the rust side, so we have to do a name check.
return handler(m)
# Raise ValueError (not TypeError) as per https://docs.pydantic.dev/latest/errors/errors/
if not isinstance(m, CallableModel):
raise ValueError(f"{m} is not a CallableModel: {type(m)}")
Expand Down
13 changes: 13 additions & 0 deletions ccflow/tests/test_callable.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,19 @@ def __call__(self, context: NullContext) -> GenericResult[float]:
with self.assertRaises(TypeError):
MyCallable()

def test_generic_validates_assignment(self):
class MyCallable(CallableModelGenericType[NullContext, GenericResult[int]]):
x: int = 1

@Flow.call
def __call__(self, context: NullContext) -> GenericResult[int]:
self.x = 5
assert self.x == 5
return GenericResult[float](value=self.x)

m = MyCallable()
self.assertEqual(m(NullContext()).value, 5)


class TestCallableModelDeps(TestCase):
def test_basic(self):
Expand Down