Skip to content

Commit

Permalink
fix is_optional_type or not return true for all union types (#2824)
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Dittamo <[email protected]>
  • Loading branch information
pvditt authored Oct 16, 2024
1 parent 5b3b33b commit de4e743
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 1 addition & 2 deletions flytekit/core/type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1751,8 +1751,7 @@ def __init__(self):

@staticmethod
def is_optional_type(t: Type) -> bool:
"""Return True if `t` is a Union or Optional type."""
return _is_union_type(t) or type(None) in get_args(t)
return _is_union_type(t) and type(None) in get_args(t)

@staticmethod
def get_sub_type_in_optional(t: Type[T]) -> Type[T]:
Expand Down
2 changes: 2 additions & 0 deletions tests/flytekit/unit/core/test_type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,8 @@ def test_union_transformer():
assert not UnionTransformer.is_optional_type(str)
assert UnionTransformer.get_sub_type_in_optional(typing.Optional[int]) == int
assert UnionTransformer.get_sub_type_in_optional(int | None) == int
assert not UnionTransformer.is_optional_type(typing.Union[int, str])
assert UnionTransformer.is_optional_type(typing.Union[int, None])


def test_union_guess_type():
Expand Down

0 comments on commit de4e743

Please sign in to comment.