This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Subclassing Enum with ipaddress.IPv4Network/IPv6Network raises TypeError.
Type: crash Stage: resolved
Components: Library (Lib) Versions: Python 3.10, Python 3.9
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: barry, eli.bendersky, ethan.furman, felixxm
Priority: high Keywords: patch

Created on 2021-01-07 06:39 by felixxm, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 24154 merged ethan.furman, 2021-01-07 20:31
PR 24155 merged ethan.furman, 2021-01-07 21:25
Messages (5)
msg384563 - (view) Author: Mariusz Felisiak (felixxm) * Date: 2021-01-07 06:39
We noticed a behavior change in Python3.10.0a4 (it works properly in Python3.10.0a3) when running Django's test suite[1]. Subclassing `enum.Enum` with `ipaddress.IPv4Network/IPv6Network` raises `TypeError`, e.g.

>>> import enum
>>> import ipaddress
>>> class NewEnum(ipaddress.IPv4Address, enum.Enum):
...     pass
>>> class NewEnum(ipaddress.IPv4Network, enum.Enum):
...     pass
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/", line 239, in __new__
    enum_class.__bases__ = enum_class.__bases__[1:] #or (object, )
  File "/usr/local/lib/python3.10/", line 483, in __setattr__
    super().__setattr__(name, value)
TypeError: __bases__ assignment: 'IPv4Network' object layout differs from '_NoInitSubclass'

It still works for `ipaddress.IPv4Address/IPv6Address`.

msg384591 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2021-01-07 15:06
That would be due to some changes to try and get `Enum` and `__init_subclass__` to work together.

I'll revert those changes.  Thank you for the report.
msg384605 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2021-01-07 21:18
New changeset a581a868d97f649aedf868a1d27865a10925c73a by Ethan Furman in branch 'master':
bpo-42851: [Enum] remove brittle __init_subclass__ support (GH-24154)
msg384608 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2021-01-07 21:56
New changeset 9ab4dd452287169f08a8cf4d4c68c2139f8de714 by Ethan Furman in branch '3.9':
[3.9] bpo-42851: [Enum] remove brittle __init_subclass__ support (GH-24154) (GH-24155)
msg384639 - (view) Author: Mariusz Felisiak (felixxm) * Date: 2021-01-08 06:59
Ethan, Thanks for the patch.
Date User Action Args
2022-04-11 14:59:39adminsetgithub: 87017
2021-01-08 18:13:45ethan.furmansetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.9
2021-01-08 06:59:11felixxmsetmessages: + msg384639
2021-01-07 21:56:05ethan.furmansetmessages: + msg384608
2021-01-07 21:25:19ethan.furmansetpull_requests: + pull_request22983
2021-01-07 21:18:15ethan.furmansetmessages: + msg384605
2021-01-07 20:31:05ethan.furmansetkeywords: + patch
stage: patch review
pull_requests: + pull_request22982
2021-01-07 15:06:37ethan.furmansetpriority: normal -> high
assignee: ethan.furman
messages: + msg384591
2021-01-07 06:39:43felixxmcreate