Skip to content

Fix __str__ for enums in python 3.11 - #13390

Merged
pzread merged 3 commits into
iree-org:mainfrom
pzread:fix-enum-str
May 3, 2023
Merged

pzread merged 3 commits into
iree-org:mainfrom
pzread:fix-enum-str

Conversation

@pzread

@pzread pzread commented May 3, 2023 •

Copy link
Copy Markdown
Contributor

Python 3.11 changes the behaviors on Enum and the __str__ in the parent class now can't override the default one from enum.Enum. Move the __str__ into enum class itself to properly override the default one.

It's a little bit unclear to me why it doesn't follow MRO to use the __str__ in the first parent class, but seems like this is the reason:

Changed Enum and Flag so that members are now defined before init_subclass() is called; dir() now includes methods, etc., from mixed-in data types.

This change should solve the test failures on macos arm64 (which is using python 3.11 to run tests).

References:

@pzread pzread changed the title Fix __str__ for enums in Python 3.11 Fix __str__ for enums in python 3.11 May 3, 2023
@pzread
pzread marked this pull request as ready for review May 3, 2023 20:01
@pzread
pzread requested a review from GMNGeoffrey as a code owner May 3, 2023 20:01

@GMNGeoffrey GMNGeoffrey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that's weird, Python...

@pzread
pzread merged commit 61b2500 into iree-org:main May 3, 2023
NatashaKnk pushed a commit to NatashaKnk/iree that referenced this pull request Jul 6, 2023
Python 3.11 changes the behaviors on Enum and the `__str__` in the
parent class now can't override the default one from `enum.Enum`. Move
the `__str__` into enum class itself to properly override the default
one.
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