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
…2825)

Signed-off-by: Paul Dittamo <[email protected]>
Co-authored-by: Paul Dittamo <[email protected]>
  • Loading branch information
eapolinario and pvditt authored Oct 16, 2024
1 parent 54923af commit 1e7306c
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 @@ -1525,8 +1525,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 @@ -1707,6 +1707,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 1e7306c

Please sign in to comment.