Repository navigation
AttributeError in 3.11 on repr() of enum member if the enum has a non-Enum EnumType parent #102558
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Mar 9, 2023 - addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory3.11only security fixesonly security fixes
on Mar 9, 2023 Reproduced also on Linux in case it's important:
Python 3.11.2 (main, Mar 1 2023, 14:46:02) [GCC 10.2.1 20210110] on linuxReacted by JP Hutchins- added a commit that references this issue
on Mar 9, 2023 Wow, this must be the fastest fix I've ever seen implemented in response to a random dude's complaint in the history of paid SLA contracts. Oh wait, I don't have any contract. Kudos and thanks.
Reacted by Kirill PodoprigoraReacted by Kirill Podoprigora@ethanfurman
I submitted the patch but not sure it is the correct fix(closer to work around)
So please let me know if you have a better fix. (or you can direct fix this)Merging in the work-around; will investigate further as time allows.
Reacted by vashek and Donghee Na@vashek What is your actual use-case for that coding style? Making a non-
Enumclass withEnumMetaas the type is not the intended usage.@ethanfurman Now I feel a bit silly, because it seems like I brought it upon myself completely needlessly and wasted your time. Sorry.
What I'm doing is I have a class with some class methods for enums, and then I'm mixing it into the actual enums. I guess when I did that, my thought process was "if I'm going to mix in another class into the enum, and the enum has a special metaclass, surely I can't just use an ordinary class with its ordinary metaclass -- surely the mixed-in classes must have a common metaclass". Now that I googled and read up on the subject, I think I now understand that this would have only been a problem if my base class used a different metaclass. I don't remember whether I had ever tried it without the metaclass -- maybe I haven't. I tried now and it seems to work fine.
I mean the fix is still nice, but I suppose the "bug" was only ever encountered by me and completely unnecessarily anyway, apparently.
No worries, glad it ended up being an easy fix for us both.
Thanks, looks like this was fixed and backported!
- changed the title
[-]AttributeError in 3.11 on repr() of enum member if the enum has multiple superclasses[/-][+]AttributeError in 3.11 on repr() of enum member if the enum has a non-Enum EnumType parent[/+]on Mar 27, 2023
Bug report
In CPython 3.11.0 - 3.11.2 (but not 3.10.10), I get a weird AttributeError when repr() is called on an Enum member of a class that was defined using multiple inheritance. Minimal code to reproduce:
With Python up to 3.10, the output is:
With Python 3.11, the output is:
Your environment
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32(But reproduced also on 3.11.2)
Linked PRs