Skip to content

Commit

Permalink
fix enum type assertion with python versions less than 3.12 (#2873)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Sola <daniel.sola@union.ai>
  • Loading branch information
dansola authored Oct 28, 2024
1 parent 8021cb5 commit 6d3d3e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flytekit/core/type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ def assert_type(self, t: Type[enum.Enum], v: T):
return

val = v.value if isinstance(v, enum.Enum) else v
if val not in t:
if val not in [t_item.value for t_item in t]:
raise TypeTransformerFailedError(f"Value {v} is not in Enum {t}")


Expand Down
22 changes: 22 additions & 0 deletions tests/flytekit/unit/core/test_enum_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from enum import Enum

from flytekit import task, workflow


def test_dynamic_local():
class Color(Enum):
RED = 'red'
GREEN = 'green'
BLUE = 'blue'

@task
def my_task(c: Color) -> Color:
print(c)
return c

@workflow
def wf(c: Color) -> Color:
return my_task(c=c)

res = wf(c=Color.RED)
assert res == Color.RED

0 comments on commit 6d3d3e7

Please sign in to comment.