Skip to content

Commit 81fcc92

Browse files
committed
Allow Any output type with a warning
1 parent f51f29a commit 81fcc92

File tree

3 files changed

+440
-1
lines changed

3 files changed

+440
-1
lines changed

python/coglet/inspector.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,28 @@ def _input_adt(
127127
)
128128

129129

130+
# Mimic PrimitiveType behavior to support Any output type
131+
class AnyType:
132+
def normalize(self, value: Any) -> Any:
133+
return value
134+
135+
def json_type(selfself) -> dict[str, Any]:
136+
# Compat: legacy Cog does not even add {"type": "object"}
137+
return {}
138+
139+
def json_encode(self, value: Any) -> Any:
140+
return value
141+
142+
143+
_any_type = AnyType()
144+
145+
130146
def _output_adt(tpe: type) -> adt.Output:
147+
if tpe is Any:
148+
print(
149+
'Warning: use of Any as output type is error prone and highly-discouraged'
150+
)
151+
return adt.Output(kind=adt.Kind.SINGLE, type=_any_type) # type: ignore
131152
if inspect.isclass(tpe) and _check_parent(tpe, api.BaseModel):
132153
assert tpe.__name__ == 'Output', 'output type must be named Output'
133154
fields = {}
@@ -141,7 +162,6 @@ def _output_adt(tpe: type) -> adt.Output:
141162

142163
origin = typing.get_origin(tpe)
143164
kind = None
144-
ft = None
145165
if origin in {typing.get_origin(Iterator), typing.get_origin(AsyncIterator)}:
146166
kind = adt.Kind.ITERATOR
147167
t_args = typing.get_args(tpe)

0 commit comments

Comments
 (0)