-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
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
StrEnum subclasses cannot be created #79090
Comments
from enum import Enum, unique
class StrEnum(str, Enum):
def __new__(cls, *args, **kwargs):
for a in args:
if not isinstance(a, str):
raise TypeError("Enumeration '%s' (%s) is not"
" a string" % (a, type(a).__name__))
return super(StrEnum, cls).__new__(cls, *args, **kwargs)
@unique
class Decision(StrEnum):
"""Decision results/strategy enumeration."""
REVERT = "REVERT"
REVERT_ALL = "REVERT_ALL"
RETRY = "RETRY" Traceback (most recent call last):
File "test", line 14, in <module>
class Decision(StrEnum):
File ".../cpython/Lib/enum.py", line 222, in __new__
enum_member._value_ = member_type(*args)
File ".../cpython/Lib/enum.py", line 309, in __call__
return cls.__new__(cls, value)
File ".../cpython/Lib/enum.py", line 545, in __new__
return cls._missing_(value)
File ".../cpython/Lib/enum.py", line 558, in _missing_
raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 'REVERT' is not a valid StrEnum |
Ethan, do you an ETA of a fix for this? 3.7.1 final is scheduled for fewer than 24 hours from now but if it's truly a release blocker I will hold for a fix and probably do a rc2 instead. |
It really is. I got a message from Michal Arbet from OpenStack about it. I just finished the fix and am currently running the tests locally. Is it okay to have the PR directly against 3.7 instead of doing 3.8 first and backporting? |
Great. Thanks!
If you want but it's probably easier to do it the normal way and let the bot do the backport, assuming master and 3.7 are still similar in that area. |
Hi Ethan, the issue appears with your patch 0c076ca is the first bad commit
(found with git bisect and your test) |
git bisect start |
Ethan, I think you have fixed the issue, could you close this issue? Thank you |
Stéphane, thanks for the tip about bisect! |
Can you please merge a NEWS item for this issue using blurb since it is a user-visible problem? I'll cherry-pick it into the 3.7.1 final. |
On 10/12/2018 09:52 PM, Ned Deily wrote: > Can you please merge a NEWS item for this issue using blurb since it I don't believe the problem exists in 3.7.0 -- but I also don't know how If you can tell me how to get to whatever commit represents 3.7.0 I'm |
My concern was that it seemed like at least one user had run into this while running 3.7.1rc1 (?), if I understood your comment; if so, I think we should mention in the changelog that the problem was fixed in rc2. In any case, the state of the code for any release is captured as a git tag as described in the devguide. As always, when switching versions, it's important to start with a clean build directory (make distclean or git clean -fdxq may help). git checkout v3.7.0 |
Working on getting that news entry. |
Okay, the patch is here: https://github.com/ethanfurman/cpython/tree/enum_news_entry But I managed to screw something up, and my wife just got hit by a car so this is now a really low priority. Ned, if you could grab the relevant pieces from the wreck that is that branch I would be grateful. |
Hi Ethan and Ned, I am not fluent with the code of the Enum, but maybe I could work on this issue and try to finish it. Ethan, I am really sorry for your wife, take care of her. |
Thanks, Stéphane, but I’ve already taken care of it. I’ll be closing the issue shortly. (And ditto on the best wishes, Ethan.) |
Hi Ned, good news (I hope the best for the wife of Ethan) |
NEWS entry added for 3.7.1 and master. Closing again. |
Thank you both. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: