def _maybe_unroll_union(cls, info: TypeInfo) -> TypeInfo: if is_union(info.type): assert len(info.args) > 1 if cls._all_types_match(ModelT, info.args): return _TypeInfo_from_type(ModelT, optional=info.is_optional) elif cls._all_types_match(LITERAL_TYPES, info.args): return _TypeInfo_from_type(info.args[0], optional=info.is_optional) return info
def create_if_compatible(cls, typ: Type, *, root: 'RootNode') -> Optional['Node']: if is_union(typ): return cls(typ, root=root) return None
def test_is_union(input, expected): assert is_union(input) == expected