classification
Title: StrEnum subclasses cannot be created
Type: behavior Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: ethan.furman, matrixise, ned.deily
Priority: Keywords: 3.7regression, patch

Created on 2018-10-05 20:12 by ethan.furman, last changed 2018-10-20 17:16 by ethan.furman. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 9737 merged ethan.furman, 2018-10-06 05:41
PR 9738 merged miss-islington, 2018-10-06 06:30
PR 9995 merged ned.deily, 2018-10-20 04:32
Messages (22)
msg327182 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2018-10-05 20:12
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
msg327207 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-06 02:12
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.
msg327209 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2018-10-06 02:20
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?
msg327210 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-06 02:22
> I just finished the fix and am currently running the tests locally.

Great. Thanks!

> Is it okay to have the PR directly against 3.7 instead of doing 3.8 first and backporting?

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.
msg327215 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2018-10-06 04:46
Hi Ethan,

the issue appears with your patch 

0c076caaa82a9c6596e1fe1dbe6384d53f30a1a3 is the first bad commit
commit 0c076caaa82a9c6596e1fe1dbe6384d53f30a1a3
Author: Ethan Furman <ethan@stoneleaf.us>
Date:   Fri Sep 21 22:26:32 2018 -0700

    [3.7] bpo-29577: Enum: mixin classes don't mix well with already mixed Enums (GH-9328) (GH-9486)
    
    * bpo-29577: allow multiple mixin classes


(found with git bisect and your test)
msg327216 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2018-10-06 04:47
git bisect start
# bad: [1596fea0a329e1f5e4cce0135724881ca5f1d341] bpo-34899: Fix a possible assertion failure due to int_from_bytes_impl() (GH-9705)
git bisect bad 1596fea0a329e1f5e4cce0135724881ca5f1d341
# good: [84b0129b5e0a0e22aad22ae8db2e3833a228aa57] _Py_CoerceLegacyLocale() restores LC_CTYPE on fail (GH-9044) (GH-9046)
git bisect good 84b0129b5e0a0e22aad22ae8db2e3833a228aa57
# good: [470a435f3b42c9be5fdb7f7b04f3df5663ba7305] bpo-34623: Use XML_SetHashSalt in _elementtree (GH-9146)
git bisect good 470a435f3b42c9be5fdb7f7b04f3df5663ba7305
# bad: [92ad2612bef198f2e3f8f09bf552189e27afcc4e] bpo-1529353: IDLE: Squeezer What's New for 3.6.7 (GH-9567)
git bisect bad 92ad2612bef198f2e3f8f09bf552189e27afcc4e
# good: [e5fde1f992e94f166415ab96d874ed1d2e0c8004] bpo-34537: Fix test_gdb:test_strings with LC_ALL=C (GH-9483)
git bisect good e5fde1f992e94f166415ab96d874ed1d2e0c8004
# bad: [394e55a9279d17240ef6fe85d3b4ea3fe7b6dff5] [3.7] bpo-17239: Disable external entities in SAX parser (GH-9217) (GH-9511)
git bisect bad 394e55a9279d17240ef6fe85d3b4ea3fe7b6dff5
# bad: [44989bc2696320cf55ae6f329aaf58edd49d792a] bpo-34472: Add data descriptor signature to zipfile (GH-8871) (GH-9399)
git bisect bad 44989bc2696320cf55ae6f329aaf58edd49d792a
# good: [c00f7037df3607c89323e68db3ab996b7df394de] bpo-34759: Fix error handling in ssl 'unwrap()' (GH-9468)
git bisect good c00f7037df3607c89323e68db3ab996b7df394de
# bad: [0c076caaa82a9c6596e1fe1dbe6384d53f30a1a3] [3.7] bpo-29577: Enum: mixin classes don't mix well with already mixed Enums (GH-9328) (GH-9486)
git bisect bad 0c076caaa82a9c6596e1fe1dbe6384d53f30a1a3
# first bad commit: [0c076caaa82a9c6596e1fe1dbe6384d53f30a1a3] [3.7] bpo-29577: Enum: mixin classes don't mix well with already mixed Enums (GH-9328) (GH-9486)
msg327228 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2018-10-06 06:29
New changeset cd45385ffad8910293e5659cfe7ab036e70613b7 by Ethan Furman in branch 'master':
bpo-34909: keep searching mixins until base class is found (GH-9737)
https://github.com/python/cpython/commit/cd45385ffad8910293e5659cfe7ab036e70613b7
msg327234 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2018-10-06 07:43
New changeset 453b3b0e87cb16345c276b9064a4480ce3794a74 by Ethan Furman (Miss Islington (bot)) in branch '3.7':
bpo-34909: keep searching mixins until base class is found (GH-9737) (GH-9738)
https://github.com/python/cpython/commit/453b3b0e87cb16345c276b9064a4480ce3794a74
msg327245 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2018-10-06 13:36
Ethan,

I think you have fixed the issue, could you close this issue?

Thank you
msg327254 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2018-10-06 17:38
Stéphane, thanks for the tip about bisect!
msg327624 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-13 04:52
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.
msg327773 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2018-10-15 18:43
On 10/12/2018 09:52 PM, Ned Deily wrote:

 > 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.

I don't believe the problem exists in 3.7.0 -- but I also don't know how 
to select the 3.7.0 "branch"/"bookmark"/"tag"/"whatever-it's-called" to 
build and test myself.

If you can tell me how to get to whatever commit represents 3.7.0 I'm 
happy to test.
msg327794 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-15 21:54
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

https://devguide.python.org/devcycle/#development-cycle
msg327866 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2018-10-17 06:39
Working on getting that news entry.
msg327930 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2018-10-18 04:00
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.
msg328123 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-20 04:44
New changeset 8c9fd9c91ba748df68a11e3bf216fa158314c9b5 by Ned Deily in branch 'master':
bpo-34909: NEWS entry (GH-9995)
https://github.com/python/cpython/commit/8c9fd9c91ba748df68a11e3bf216fa158314c9b5
msg328140 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2018-10-20 14:49
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.
msg328144 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-20 15:07
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.)
msg328153 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2018-10-20 15:37
Hi Ned, good news (I hope the best for the wife of Ethan)
msg328166 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-20 16:57
New changeset 03ca8b5f23e9fe122bb0ca80397a2481c10cd7c4 by Ned Deily in branch '3.7':
bpo-34909: NEWS entry.
https://github.com/python/cpython/commit/03ca8b5f23e9fe122bb0ca80397a2481c10cd7c4
msg328169 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-20 17:08
NEWS entry added for 3.7.1 and master.  Closing again.
msg328172 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2018-10-20 17:16
Thank you both.
History
Date User Action Args
2018-10-20 17:16:13ethan.furmansetmessages: + msg328172
2018-10-20 17:08:50ned.deilysetpriority: deferred blocker ->
status: open -> closed
messages: + msg328169

stage: patch review -> resolved
2018-10-20 16:57:26ned.deilysetmessages: + msg328166
2018-10-20 15:37:09matrixisesetmessages: + msg328153
2018-10-20 15:07:41ned.deilysetmessages: + msg328144
2018-10-20 14:49:44matrixisesetmessages: + msg328140
2018-10-20 04:44:29ned.deilysetmessages: + msg328123
2018-10-20 04:32:50ned.deilysetstage: commit review -> patch review
pull_requests: + pull_request9337
2018-10-18 04:00:33ethan.furmansetmessages: + msg327930
2018-10-17 06:39:47ethan.furmansetmessages: + msg327866
2018-10-15 21:54:48ned.deilysetmessages: + msg327794
2018-10-15 18:43:15ethan.furmansetmessages: + msg327773
2018-10-13 04:52:08ned.deilysetpriority: release blocker -> deferred blocker
status: closed -> open
messages: + msg327624

stage: resolved -> commit review
2018-10-06 17:38:16ethan.furmansetstatus: open -> closed
resolution: fixed
messages: + msg327254

stage: patch review -> resolved
2018-10-06 13:36:16matrixisesetmessages: + msg327245
2018-10-06 07:43:24ethan.furmansetmessages: + msg327234
2018-10-06 06:30:06miss-islingtonsetpull_requests: + pull_request9125
2018-10-06 06:29:40ethan.furmansetmessages: + msg327228
2018-10-06 05:41:44ethan.furmansetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request9124
2018-10-06 04:47:46matrixisesetmessages: + msg327216
2018-10-06 04:46:02matrixisesetnosy: + matrixise
messages: + msg327215
2018-10-06 02:22:48ned.deilysetmessages: + msg327210
2018-10-06 02:20:02ethan.furmansettype: behavior
messages: + msg327209
stage: test needed -> needs patch
2018-10-06 02:12:59ned.deilysetmessages: + msg327207
2018-10-05 20:12:48ethan.furmancreate