Issue41517
Created on 2020-08-10 17:47 by talsuk5, last changed 2020-09-16 14:43 by ethan.furman. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 22271 | merged | ethan.furman, 2020-09-16 05:47 | |
| PR 22278 | merged | miss-islington, 2020-09-16 14:12 | |
| PR 22279 | merged | miss-islington, 2020-09-16 14:12 | |
| Messages (12) | |||
|---|---|---|---|
| msg375133 - (view) | Author: Tal Suhareanu (talsuk5) | Date: 2020-08-10 17:47 | |
when inheriting an implemented enum, we get a runtime error But when creating a multiple inheritance like the following, it works… so something feels broken in the enum mechanism ------------------------------------ from enum import IntEnum, Enum class A(IntEnum): a = 1 class B(A, Enum): b= 1 print(B.b) ------------------------------------ |
|||
| msg375135 - (view) | Author: Eric V. Smith (eric.smith) * | Date: 2020-08-10 18:55 | |
Could you provide code which demonstrates the problem? |
|||
| msg375139 - (view) | Author: Tal Suhareanu (talsuk5) | Date: 2020-08-10 19:01 | |
Eric V. Smith it's in the first comment |
|||
| msg375141 - (view) | Author: Eric V. Smith (eric.smith) * | Date: 2020-08-10 19:06 | |
With Python 3.7.4, which is all I have handy, that code does not give a runtime error. It prints "B.b". Your text says code "when creating a multiple inheritance like the following, it works". It sounds like you know the code sample works. So I don't understand what code gives a runtime error. What type of error are you seeing? |
|||
| msg375143 - (view) | Author: Tal Suhareanu (talsuk5) | Date: 2020-08-10 19:24 | |
sorry, I'll explain. by "when inheriting an implemented enum, we get a runtime error" I refer to this https://docs.python.org/3/library/enum.html#restricted-enum-subclassing You shouldn't be able to subclass an enum, yet I just showed a loophole. my example code shows you can subclass an enum by using a trick, multiple inheritance. I hope it's more clear now :) btw it also works with regular Enum inheritance (I just used IntEnum for simplicity) |
|||
| msg375145 - (view) | Author: Ethan Furman (ethan.furman) * | Date: 2020-08-10 19:48 | |
The problem is that class B should raise an error as class A already has members. |
|||
| msg375147 - (view) | Author: Tal Suhareanu (talsuk5) | Date: 2020-08-10 19:54 | |
Ethan Furman bullseye! thanks for clarifying |
|||
| msg375157 - (view) | Author: Steven D'Aprano (steven.daprano) * | Date: 2020-08-10 23:42 | |
The documentation says: "Allowing subclassing of enums that define members would lead to a violation of some important invariants of types and instances." but it isn't clear what those invariants are, or why it is more of a problem for enums than any other subclassing situation. Could the docs be updated to explain why it is prohibited? |
|||
| msg376921 - (view) | Author: Ethan Furman (ethan.furman) * | Date: 2020-09-15 00:36 | |
To answer the invariant question, see this post by Guido: https://mail.python.org/pipermail/python-dev/2013-April/125716.html |
|||
| msg376994 - (view) | Author: Ethan Furman (ethan.furman) * | Date: 2020-09-16 14:12 | |
New changeset 3064dbf5df1021e85b507366a7ea448c8895efe7 by Ethan Furman in branch 'master': bpo-41517: do not allow Enums to be extended (#22271) https://github.com/python/cpython/commit/3064dbf5df1021e85b507366a7ea448c8895efe7 |
|||
| msg376997 - (view) | Author: miss-islington (miss-islington) | Date: 2020-09-16 14:31 | |
New changeset 3f4012117bf80aa7c005f8fa6fb8e1f8b1aef5d5 by Miss Islington (bot) in branch '3.8': bpo-41517: do not allow Enums to be extended (GH-22271) https://github.com/python/cpython/commit/3f4012117bf80aa7c005f8fa6fb8e1f8b1aef5d5 |
|||
| msg376998 - (view) | Author: miss-islington (miss-islington) | Date: 2020-09-16 14:35 | |
New changeset 48f99250ff319e36b15b555128cd62e408d8165f by Miss Islington (bot) in branch '3.9': bpo-41517: do not allow Enums to be extended (GH-22271) https://github.com/python/cpython/commit/48f99250ff319e36b15b555128cd62e408d8165f |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2020-09-16 14:43:14 | ethan.furman | set | status: open -> closed assignee: ethan.furman resolution: fixed stage: patch review -> resolved |
| 2020-09-16 14:35:22 | miss-islington | set | messages: + msg376998 |
| 2020-09-16 14:31:11 | miss-islington | set | messages: + msg376997 |
| 2020-09-16 14:12:25 | miss-islington | set | pull_requests: + pull_request21332 |
| 2020-09-16 14:12:14 | miss-islington | set | nosy:
+ miss-islington pull_requests: + pull_request21331 |
| 2020-09-16 14:12:04 | ethan.furman | set | messages: + msg376994 |
| 2020-09-16 05:55:57 | ethan.furman | set | versions: + Python 3.8, Python 3.9, Python 3.10, - Python 3.7 |
| 2020-09-16 05:47:05 | ethan.furman | set | keywords:
+ patch stage: patch review pull_requests: + pull_request21326 |
| 2020-09-15 00:36:02 | ethan.furman | set | messages: + msg376921 |
| 2020-08-10 23:42:29 | steven.daprano | set | nosy:
+ steven.daprano messages:
+ msg375157 |
| 2020-08-10 22:46:25 | Jeffrey.Kintscher | set | nosy:
+ Jeffrey.Kintscher |
| 2020-08-10 19:54:30 | talsuk5 | set | messages: + msg375147 |
| 2020-08-10 19:48:59 | ethan.furman | set | messages: + msg375145 |
| 2020-08-10 19:24:02 | talsuk5 | set | messages: + msg375143 |
| 2020-08-10 19:06:00 | eric.smith | set | messages: + msg375141 |
| 2020-08-10 19:01:16 | talsuk5 | set | messages: + msg375139 |
| 2020-08-10 18:55:17 | eric.smith | set | nosy:
+ eric.smith messages: + msg375135 |
| 2020-08-10 18:09:56 | xtreak | set | nosy:
+ barry, eli.bendersky, ethan.furman |
| 2020-08-10 17:47:58 | talsuk5 | create | |