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

Conversation

dansola
Copy link
Contributor

@dansola dansola commented Oct 28, 2024

Why are the changes needed?

Follow up on: #2845

Python versions less than 3.12 don't support using in with an Enum (link).

Changed in version 3.12: Before Python 3.12, a TypeError is raised if a non-Enum-member is used in a containment check.

As a result, the linked previous PR results in a Reason unsupported operand type(s) for 'in': 'str' and 'EnumType' error.

What changes were proposed in this pull request?

Rather than checking the python version, just convert the enum items to a list and use in from there.

How was this patch tested?

from enum import Enum

from flytekit import task, workflow


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)

union run wf.py wf --c red

Success with python 3.12 but error with python 3.11.

flyteorg/flyte#5904

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

#2845

Signed-off-by: Daniel Sola <[email protected]>
Signed-off-by: Daniel Sola <[email protected]>
@wild-endeavor
Copy link
Contributor

Thanks!

@wild-endeavor wild-endeavor enabled auto-merge (squash) October 28, 2024 21:38
@wild-endeavor wild-endeavor merged commit 6d3d3e7 into master Oct 28, 2024
29 checks passed
wild-endeavor pushed a commit that referenced this pull request Oct 30, 2024
eapolinario pushed a commit that referenced this pull request Oct 30, 2024
wild-endeavor pushed a commit that referenced this pull request Oct 30, 2024
kumare3 pushed a commit that referenced this pull request Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants