Skip to content

Commit 07981f1

Browse files
committed
feedback from review
Signed-off-by: Blake <[email protected]>
1 parent b2cf456 commit 07981f1

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

flytekit/interaction/click_types.py

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import pathlib
1010
import sys
11+
import types
1112
import typing
1213
import typing as t
1314
from typing import cast, get_args
@@ -264,27 +265,6 @@ def convert(
264265
return self._datetime_from_format(value, param, ctx)
265266

266267

267-
class DateType(DateTimeType):
268-
"""
269-
A specialized type for handling date types that extends DateTimeType but returns date objects.
270-
"""
271-
272-
def convert(
273-
self, value: typing.Any, param: typing.Optional[click.Parameter], ctx: typing.Optional[click.Context]
274-
) -> typing.Any:
275-
if isinstance(value, ArtifactQuery):
276-
return value
277-
278-
# First convert using the parent DateTime logic
279-
dt_value = super().convert(value, param, ctx)
280-
281-
# Then convert to date if it's a datetime object
282-
if isinstance(dt_value, datetime.datetime):
283-
return dt_value.date()
284-
285-
return dt_value
286-
287-
288268
class DurationParamType(click.ParamType):
289269
name = "[1:24 | :22 | 1 minute | 10 days | ...]"
290270

@@ -540,13 +520,8 @@ def literal_type_to_click_type(lt: LiteralType, python_type: typing.Type) -> cli
540520
for i in range(len(lt.union_type.variants)):
541521
variant = lt.union_type.variants[i]
542522
variant_python_type = typing.get_args(python_type)[i]
543-
# Special handling for datetime.date in union types
544-
if variant_python_type is datetime.date:
545-
ct = DateType()
546-
else:
547-
ct = literal_type_to_click_type(variant, variant_python_type)
523+
ct = literal_type_to_click_type(variant, variant_python_type)
548524
cts.append(ct)
549-
550525
return UnionParamType(cts)
551526

552527
return click.UNPROCESSED
@@ -585,7 +560,14 @@ def convert(
585560
return value
586561
try:
587562
# If the expected Python type is datetime.date, adjust the value to date
588-
if self._python_type is datetime.date and isinstance(value, datetime.datetime):
563+
is_union = typing.get_origin(self._python_type) in (
564+
typing.Union,
565+
types.UnionType,
566+
)
567+
args = typing.get_args(self._python_type)
568+
is_date_type = (is_union and datetime.date in args) or self._python_type is datetime.date
569+
570+
if is_date_type and isinstance(value, datetime.datetime):
589571
# Click produces datetime, so converting to date to avoid type mismatch error
590572
value = value.date()
591573
# If the input matches the default value in the launch plan, serialization can be skipped.

0 commit comments

Comments
 (0)