Is there a way to specify a `typing.Union` return ...
# ask-community
v
Is there a way to specify a
typing.Union
return type from an
@op
that doesn’t cause Dagster to raise a
DagsterInvalidDefinitionError
? I have an
op
that should return one of two custom types depending on some of the config passed, but specifying it in the return type signature or
Out(Union[type1, type2])
raises this error. The workaround I found was to define another output type (below) but it feels unnecessary for this type of use case.
Copy code
type1_or_type2 = DagsterType(
    name="type1_or_type2",
    type_check_fn=lambda _, x: isinstance(x, type1) or isinstance(x, type2),
)