From 7cbd2b840f4b805d0c2d4ffe0a940d50f2d3de7c Mon Sep 17 00:00:00 2001 From: Adrian Rumpold Date: Thu, 9 Mar 2023 09:46:16 +0100 Subject: [PATCH] fix: Make FlyteFile compatible with Annotated[..., HashMethod] See issue #3424 --- flytekit/types/file/file.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flytekit/types/file/file.py b/flytekit/types/file/file.py index 6537f85cae9..3d4453cf6c0 100644 --- a/flytekit/types/file/file.py +++ b/flytekit/types/file/file.py @@ -272,6 +272,10 @@ def to_literal( if python_val is None: raise TypeTransformerFailedError("None value cannot be converted to a file.") + # Correctly handle `Annotated[FlyteFile, ...]` by extracting the origin type + if typing.get_origin(python_type) is typing.Annotated: + python_type = typing.get_args(python_type)[0] + if not (python_type is os.PathLike or issubclass(python_type, FlyteFile)): raise ValueError(f"Incorrect type {python_type}, must be either a FlyteFile or os.PathLike")