classification
Title: enum: Mixin and int base class regression in 3.8.6
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: WildCard65, barry, eli.bendersky, ethan.furman, miss-islington, puddly
Priority: normal Keywords: patch

Created on 2020-09-30 04:21 by puddly, last changed 2020-12-08 03:21 by ethan.furman. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 22487 merged ethan.furman, 2020-10-01 23:34
PR 23672 merged miss-islington, 2020-12-07 08:19
PR 23673 merged miss-islington, 2020-12-07 08:19
Messages (5)
msg377692 - (view) Author: (puddly) Date: 2020-09-30 04:21
The following code worked in 3.8.5 but does not in 3.8.6 due to the fix for #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__()
```
msg377709 - (view) Author: William Pickard (WildCard65) * Date: 2020-09-30 15:51
Actually, this is an issue with native types in general that define a 'tp_new' slot value ('!= NULL').
msg382623 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-12-07 08:17
New changeset c266736ec1f9ebef38b134ceb4832df015711b38 by Ethan Furman in branch 'master':
bpo-41889: [Enum] fix multiple-inheritance regression (GH-22487)
https://github.com/python/cpython/commit/c266736ec1f9ebef38b134ceb4832df015711b38
msg382699 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-12-07 23:50
New changeset 699e5e448919283578afe445069ab93b34bf8eae by Miss Islington (bot) in branch '3.8':
bpo-41889: [Enum] fix multiple-inheritance regression (GH-22487) (GH-23672)
https://github.com/python/cpython/commit/699e5e448919283578afe445069ab93b34bf8eae
msg382700 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-12-07 23:51
New changeset be52ca45d9eb9c3e8941e46ddc67a210f0f4c6fa by Miss Islington (bot) in branch '3.9':
bpo-41889: [Enum] fix multiple-inheritance regression (GH-22487) (GH-23673)
https://github.com/python/cpython/commit/be52ca45d9eb9c3e8941e46ddc67a210f0f4c6fa
History
Date User Action Args
2020-12-08 03:21:43ethan.furmansetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-12-07 23:51:19ethan.furmansetmessages: + msg382700
2020-12-07 23:50:27ethan.furmansetmessages: + msg382699
2020-12-07 08:19:40miss-islingtonsetpull_requests: + pull_request22539
2020-12-07 08:19:33miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request22538
2020-12-07 08:17:43ethan.furmansetmessages: + msg382623
2020-10-01 23:35:19ethan.furmansetassignee: ethan.furman
2020-10-01 23:34:28ethan.furmansetkeywords: + patch
stage: patch review
pull_requests: + pull_request21505
2020-09-30 15:51:26WildCard65setnosy: + WildCard65
messages: + msg377709
2020-09-30 04:21:36puddlycreate