Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix enum type assertion with python versions less than 3.12 #2873

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading