Skip to content

Commit

Permalink
update comments
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Su <[email protected]>
  • Loading branch information
pingsutw committed Sep 9, 2022
1 parent cf10b84 commit ece1a96
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions flytekit/core/type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ def _fix_val_int(self, t: typing.Type, val: typing.Any) -> typing.Any:

if get_origin(t) is typing.Union and type(None) in get_args(t):
# Handle optional type. e.g. Optional[int], Optional[dataclass]
# Marshmallow doesn't support union type, so the type here is always an optional type.
# https://github.com/marshmallow-code/marshmallow/issues/1191#issuecomment-480831796
# Note: Typing.Union[None, int] is also an optional type, but Marshmallow does not support it.
return self._fix_val_int(get_args(t)[0], val)

if dataclasses.is_dataclass(t):
Expand Down
2 changes: 1 addition & 1 deletion tests/flytekit/unit/core/test_type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_list_of_dataclass_getting_python_value():
@dataclass()
class Bar(object):
v: typing.Union[int, None]
w: typing.Union[None, str]
w: typing.Optional[str]
x: float
y: str
z: typing.Dict[str, bool]
Expand Down

0 comments on commit ece1a96

Please sign in to comment.