Skip to content

Commit

Permalink
update thomas's advice
Browse files Browse the repository at this point in the history
Signed-off-by: Future-Outlier <[email protected]>
  • Loading branch information
Future-Outlier committed Feb 3, 2025
1 parent b9298cd commit 3fe9801
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion flytekit/core/type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1915,7 +1915,11 @@ async def async_to_literal(
continue

if is_ambiguous:
raise TypeError(f"Ambiguous choice of variant for union type.\n" f"Potential types: {potential_types}\n")
raise TypeError(
f"Ambiguous choice of variant for union type.\n"

Check warning on line 1919 in flytekit/core/type_engine.py

View check run for this annotation

Codecov / codecov/patch

flytekit/core/type_engine.py#L1919

Added line #L1919 was not covered by tests
f"Potential types: {potential_types}\n"
"These types are structurally the same, because it's attributes have the same names and associated types."
)

if found_res:
return Literal(scalar=Scalar(union=Union(value=res, stored_type=res_type)))
Expand Down
9 changes: 7 additions & 2 deletions tests/flytekit/unit/core/test_unions.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ def t1() -> typing.Union[A, B]:

with pytest.raises(
TypeError,
match=("Ambiguous choice of variant for union type.\n"
"Potential types: \\[<class '.*\\.A'>, <class '.*\\.B'>\\]")
match=(
"Failed to convert outputs of task '.*?' at position 0\\.\n"
"Failed to convert type <class '.*?\\.A'> to type typing\\.Union\\[.*?\\]\\.\n"
"Error Message: Ambiguous choice of variant for union type\\.\n"
"Potential types: \\[<class '.*?\\.A'>, <class '.*?\\.B'>\\]\n"
"These types are structurally the same, because it's attributes have the same names and associated types\\."
),
):
t1()

0 comments on commit 3fe9801

Please sign in to comment.