Skip to content

Commit

Permalink
Remove typing-inspect dependency (#2327)
Browse files Browse the repository at this point in the history
* Remove typing-inspect dependencies

Signed-off-by: Thomas J. Fan <[email protected]>

* DOC Adds docstring

Signed-off-by: Thomas J. Fan <[email protected]>

---------

Signed-off-by: Thomas J. Fan <[email protected]>
Signed-off-by: Jan Fiedler <[email protected]>
  • Loading branch information
thomasjpfan authored and fiedlerNr9 committed Jul 25, 2024
1 parent 34a07ed commit 8caf617
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 15 additions & 2 deletions flytekit/core/type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from mashumaro.codecs.json import JSONDecoder, JSONEncoder
from mashumaro.mixins.json import DataClassJSONMixin
from typing_extensions import Annotated, get_args, get_origin
from typing_inspect import is_union_type

from flytekit.core.annotation import FlyteAnnotation
from flytekit.core.context_manager import FlyteContext
Expand Down Expand Up @@ -1516,6 +1515,19 @@ def _are_types_castable(upstream: LiteralType, downstream: LiteralType) -> bool:
return False


def _is_union_type(t):
"""Returns True if t is a Union type."""

if sys.version_info >= (3, 10):
import types

UnionType = types.UnionType
else:
UnionType = None

return t is typing.Union or get_origin(t) is Union or UnionType and isinstance(t, UnionType)


class UnionTransformer(TypeTransformer[T]):
"""
Transformer that handles a typing.Union[T1, T2, ...]
Expand All @@ -1526,7 +1538,8 @@ def __init__(self):

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

@staticmethod
def get_sub_type_in_optional(t: Type[T]) -> Type[T]:
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ dependencies = [
"s3fs>=2023.3.0,!=2024.3.1",
"statsd>=3.0.0,<4.0.0",
"typing_extensions",
"typing-inspect",
"urllib3>=1.22,<2.0.0",
]
classifiers = [
Expand Down

0 comments on commit 8caf617

Please sign in to comment.