@@ -1769,6 +1769,19 @@ def _type_essence(x: LiteralType) -> LiteralType:
17691769
17701770
17711771def _are_types_castable (upstream : LiteralType , downstream : LiteralType ) -> bool :
1772+ if upstream .union_type is not None :
1773+ # for each upstream variant, there must be a compatible type downstream
1774+ for v in upstream .union_type .variants :
1775+ if not _are_types_castable (v , downstream ):
1776+ return False
1777+ return True
1778+
1779+ if downstream .union_type is not None :
1780+ # there must be a compatible downstream type
1781+ for v in downstream .union_type .variants :
1782+ if _are_types_castable (upstream , v ):
1783+ return True
1784+
17721785 if upstream .collection_type is not None :
17731786 if downstream .collection_type is None :
17741787 return False
@@ -1814,19 +1827,6 @@ def _are_types_castable(upstream: LiteralType, downstream: LiteralType) -> bool:
18141827
18151828 return True
18161829
1817- if upstream .union_type is not None :
1818- # for each upstream variant, there must be a compatible type downstream
1819- for v in upstream .union_type .variants :
1820- if not _are_types_castable (v , downstream ):
1821- return False
1822- return True
1823-
1824- if downstream .union_type is not None :
1825- # there must be a compatible downstream type
1826- for v in downstream .union_type .variants :
1827- if _are_types_castable (upstream , v ):
1828- return True
1829-
18301830 if upstream .enum_type is not None :
18311831 # enums are castable to string
18321832 if downstream .simple == SimpleType .STRING :
@@ -2113,7 +2113,7 @@ async def dict_to_generic_literal(
21132113 ),
21142114 metadata = {"format" : "pickle" },
21152115 )
2116- raise TypeTransformerFailedError (f"Cannot convert `{ v } ` to Flyte Literal.\n " f"Error Message: { e } " )
2116+ raise TypeTransformerFailedError (f"Cannot convert `{ v } ` to Flyte Literal.\n Error Message: { e } " )
21172117
21182118 @staticmethod
21192119 async def dict_to_binary_literal (
@@ -2139,7 +2139,7 @@ async def dict_to_binary_literal(
21392139 ),
21402140 metadata = {"format" : "pickle" },
21412141 )
2142- raise TypeTransformerFailedError (f"Cannot convert `{ v } ` to Flyte Literal.\n " f"Error Message: { e } " )
2142+ raise TypeTransformerFailedError (f"Cannot convert `{ v } ` to Flyte Literal.\n Error Message: { e } " )
21432143
21442144 @staticmethod
21452145 def is_pickle (python_type : Type [dict ]) -> bool :
0 commit comments