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

[BUG] EnumTransformer throws TypeError with Python 3.11 #5904

Open
2 tasks done
linhai-fn opened this issue Oct 23, 2024 · 0 comments
Open
2 tasks done

[BUG] EnumTransformer throws TypeError with Python 3.11 #5904

linhai-fn opened this issue Oct 23, 2024 · 0 comments
Assignees
Labels
bug Something isn't working flytekit FlyteKit Python related issue

Comments

@linhai-fn
Copy link

Describe the bug

EnumTransformer throws the following error when using Python 3.11:

File /fn/lib/python3.11/enum.py:742, in EnumType.__contains__(cls, member)
    735     import warnings
    736     warnings.warn(
    737             "in 3.12 __contains__ will no longer raise TypeError, but will return True or\n"
    738             "False depending on whether the value is a member or the value of a member",
    739             DeprecationWarning,
    740             stacklevel=2,
    741             )
--> 742     raise TypeError(
    743         "unsupported operand type(s) for 'in': '%s' and '%s'" % (
    744             type(member).__qualname__, cls.__class__.__qualname__))
    745 return isinstance(member, cls) and member._name_ in cls._member_map_

TypeError: unsupported operand type(s) for 'in': 'str' and 'EnumType'

The reason is due to these two lines in the assert_type:

...
val = v.value if isinstance(v, enum.Enum) else v
if val not in t:
...

The following code returns True in python 3.12. But will throw an TypeError in python 3.11 as described above.

from enum import Enum

class TestEnum(Enum):
    TEST = "Test"

TestEnum.TEST.value in TestEnum

Expected behavior

EnumTransformer shouldn't throw a TypeError when checking if a value is a member of an Enum.

Additional context to reproduce

No response

Screenshots

No response

Are you sure this issue hasn't been raised already?

  • Yes

Have you read the Code of Conduct?

  • Yes
@linhai-fn linhai-fn added bug Something isn't working untriaged This issues has not yet been looked at by the Maintainers labels Oct 23, 2024
@eapolinario eapolinario added flytekit FlyteKit Python related issue and removed untriaged This issues has not yet been looked at by the Maintainers labels Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working flytekit FlyteKit Python related issue
Projects
Status: Backlog
Development

No branches or pull requests

3 participants