Skip to content

enum: Mixin and int base class regression in 3.8.6 #86055

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

Closed
puddly mannequin opened this issue Sep 30, 2020 · 5 comments
Closed

enum: Mixin and int base class regression in 3.8.6 #86055

puddly mannequin opened this issue Sep 30, 2020 · 5 comments
Assignees
Labels
3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@puddly
Copy link
Mannequin

puddly mannequin commented Sep 30, 2020

BPO 41889
Nosy @warsaw, @ethanfurman, @WildCard65, @miss-islington, @puddly
PRs
  • bpo-41889: enum: fix multiple-inheritance regression #22487
  • [3.8] bpo-41889: [Enum] fix multiple-inheritance regression (GH-22487) #23672
  • [3.9] bpo-41889: [Enum] fix multiple-inheritance regression (GH-22487) #23673
  • 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 2020-12-08.03:21:43.846>
    created_at = <Date 2020-09-30.04:21:36.560>
    labels = ['3.8', 'type-bug', 'library', '3.9', '3.10']
    title = 'enum: Mixin and int base class regression in 3.8.6'
    updated_at = <Date 2020-12-08.03:21:43.845>
    user = 'https://github.com/puddly'

    bugs.python.org fields:

    activity = <Date 2020-12-08.03:21:43.845>
    actor = 'ethan.furman'
    assignee = 'ethan.furman'
    closed = True
    closed_date = <Date 2020-12-08.03:21:43.846>
    closer = 'ethan.furman'
    components = ['Library (Lib)']
    creation = <Date 2020-09-30.04:21:36.560>
    creator = 'puddly'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41889
    keywords = ['patch']
    message_count = 5.0
    messages = ['377692', '377709', '382623', '382699', '382700']
    nosy_count = 6.0
    nosy_names = ['barry', 'eli.bendersky', 'ethan.furman', 'WildCard65', 'miss-islington', 'puddly']
    pr_nums = ['22487', '23672', '23673']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue41889'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @puddly
    Copy link
    Mannequin Author

    puddly mannequin commented Sep 30, 2020

    The following code worked in 3.8.5 but does not in 3.8.6 due to the fix for bpo-39587:

    import enum
    
    
    class MyInt(int):
        def __new__(cls, value):
            return super().__new__(cls, value)
    
    class HexMixin:
        def __repr__(self):
            return hex(self)
    
    class MyIntEnum(HexMixin, MyInt, enum.Enum):
        pass
    
    
    class Foo(MyIntEnum):
        TEST = 1
    
    assert isinstance(Foo.TEST, MyInt)
    assert repr(Foo.TEST) == "0x1"
    

    In 3.8.6, the Foo enum itself fails to be created because HexMixin is now considered the member type instead of MyInt:

    Traceback (most recent call last):
      File "enum_test.py", line 18, in <module>
        class Foo(MyIntEnum):
      File "/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/enum.py", line 215, in __new__
        enum_member = __new__(enum_class)
    TypeError: object.__new__(Foo) is not safe, use int.__new__()
    

    @puddly puddly mannequin added 3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Sep 30, 2020
    @WildCard65
    Copy link
    Mannequin

    WildCard65 mannequin commented Sep 30, 2020

    Actually, this is an issue with native types in general that define a 'tp_new' slot value ('!= NULL').

    @ethanfurman
    Copy link
    Member

    New changeset c266736 by Ethan Furman in branch 'master':
    bpo-41889: [Enum] fix multiple-inheritance regression (GH-22487)
    c266736

    @ethanfurman
    Copy link
    Member

    New changeset 699e5e4 by Miss Islington (bot) in branch '3.8':
    bpo-41889: [Enum] fix multiple-inheritance regression (GH-22487) (GH-23672)
    699e5e4

    @ethanfurman
    Copy link
    Member

    New changeset be52ca4 by Miss Islington (bot) in branch '3.9':
    bpo-41889: [Enum] fix multiple-inheritance regression (GH-22487) (GH-23673)
    be52ca4

    @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.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant