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

StrEnum subclasses cannot be created #79090

Closed
ethanfurman opened this issue Oct 5, 2018 · 22 comments
Closed

StrEnum subclasses cannot be created #79090

ethanfurman opened this issue Oct 5, 2018 · 22 comments
Assignees
Labels
3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error

Comments

@ethanfurman
Copy link
Member

BPO 34909
Nosy @ned-deily, @ethanfurman, @matrixise
PRs
  • bpo-34909: keep searching mixins until base class is found #9737
  • [3.7] bpo-34909: keep searching mixins until base class is found (GH-9737) #9738
  • bpo-34909: NEWS entry #9995
  • 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:

    assignee = 'https://github.com/ethanfurman'
    closed_at = <Date 2018-10-20.17:08:50.098>
    created_at = <Date 2018-10-05.20:12:48.209>
    labels = ['type-bug', '3.7']
    title = 'StrEnum subclasses cannot be created'
    updated_at = <Date 2018-10-20.17:16:13.436>
    user = 'https://github.com/ethanfurman'

    bugs.python.org fields:

    activity = <Date 2018-10-20.17:16:13.436>
    actor = 'ethan.furman'
    assignee = 'ethan.furman'
    closed = True
    closed_date = <Date 2018-10-20.17:08:50.098>
    closer = 'ned.deily'
    components = []
    creation = <Date 2018-10-05.20:12:48.209>
    creator = 'ethan.furman'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 34909
    keywords = ['patch', '3.7regression']
    message_count = 22.0
    messages = ['327182', '327207', '327209', '327210', '327215', '327216', '327228', '327234', '327245', '327254', '327624', '327773', '327794', '327866', '327930', '328123', '328140', '328144', '328153', '328166', '328169', '328172']
    nosy_count = 3.0
    nosy_names = ['ned.deily', 'ethan.furman', 'matrixise']
    pr_nums = ['9737', '9738', '9995']
    priority = None
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue34909'
    versions = ['Python 3.7']

    @ethanfurman
    Copy link
    Member Author

    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

    @ned-deily
    Copy link
    Member

    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.

    @ethanfurman
    Copy link
    Member Author

    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?

    @ethanfurman ethanfurman added the type-bug An unexpected behavior, bug, or error label Oct 6, 2018
    @ned-deily
    Copy link
    Member

    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.

    @matrixise
    Copy link
    Member

    Hi Ethan,

    the issue appears with your patch

    0c076ca is the first bad commit
    commit 0c076ca
    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)

    @matrixise
    Copy link
    Member

    git bisect start
    # bad: [1596fea] bpo-34899: Fix a possible assertion failure due to int_from_bytes_impl() (GH-9705)
    git bisect bad 1596fea
    # good: [84b0129] _Py_CoerceLegacyLocale() restores LC_CTYPE on fail (GH-9044) (GH-9046)
    git bisect good 84b0129
    # good: [470a435] bpo-34623: Use XML_SetHashSalt in _elementtree (GH-9146)
    git bisect good 470a435
    # bad: [92ad261] bpo-1529353: IDLE: Squeezer What's New for 3.6.7 (GH-9567)
    git bisect bad 92ad261
    # good: [e5fde1f] bpo-34537: Fix test_gdb:test_strings with LC_ALL=C (GH-9483)
    git bisect good e5fde1f
    # bad: [394e55a] [3.7] bpo-17239: Disable external entities in SAX parser (GH-9217) (GH-9511)
    git bisect bad 394e55a
    # bad: [44989bc] bpo-34472: Add data descriptor signature to zipfile (GH-8871) (GH-9399)
    git bisect bad 44989bc
    # good: [c00f703] bpo-34759: Fix error handling in ssl 'unwrap()' (GH-9468)
    git bisect good c00f703
    # bad: [0c076ca] [3.7] bpo-29577: Enum: mixin classes don't mix well with already mixed Enums (GH-9328) (GH-9486)
    git bisect bad 0c076ca
    # first bad commit: [0c076ca] [3.7] bpo-29577: Enum: mixin classes don't mix well with already mixed Enums (GH-9328) (GH-9486)

    @ethanfurman
    Copy link
    Member Author

    New changeset cd45385 by Ethan Furman in branch 'master':
    bpo-34909: keep searching mixins until base class is found (GH-9737)
    cd45385

    @ethanfurman
    Copy link
    Member Author

    New changeset 453b3b0 by Ethan Furman (Miss Islington (bot)) in branch '3.7':
    bpo-34909: keep searching mixins until base class is found (GH-9737) (GH-9738)
    453b3b0

    @matrixise
    Copy link
    Member

    Ethan,

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

    Thank you

    @ethanfurman
    Copy link
    Member Author

    Stéphane, thanks for the tip about bisect!

    @ned-deily
    Copy link
    Member

    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.

    @ethanfurman
    Copy link
    Member Author

    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.

    @ned-deily
    Copy link
    Member

    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

    @ethanfurman
    Copy link
    Member Author

    Working on getting that news entry.

    @ethanfurman
    Copy link
    Member Author

    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.

    @ned-deily
    Copy link
    Member

    New changeset 8c9fd9c by Ned Deily in branch 'master':
    bpo-34909: NEWS entry (GH-9995)
    8c9fd9c

    @matrixise
    Copy link
    Member

    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.

    @ned-deily
    Copy link
    Member

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

    @matrixise
    Copy link
    Member

    Hi Ned, good news (I hope the best for the wife of Ethan)

    @ned-deily
    Copy link
    Member

    New changeset 03ca8b5 by Ned Deily in branch '3.7':
    bpo-34909: NEWS entry.
    03ca8b5

    @ned-deily
    Copy link
    Member

    NEWS entry added for 3.7.1 and master. Closing again.

    @ethanfurman
    Copy link
    Member Author

    Thank you both.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants