[New-bugs-announce] [issue42851] Subclassing Enum with ipaddress.IPv4Network/IPv6Network raises TypeError.

Mariusz Felisiak report at bugs.python.org
Thu Jan 7 01:39:43 EST 2021

New submission from Mariusz Felisiak <felisiak.mariusz at gmail.com>:

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/enum.py", line 239, in __new__
    enum_class.__bases__ = enum_class.__bases__[1:] #or (object, )
  File "/usr/local/lib/python3.10/enum.py", line 483, in __setattr__
    super().__setattr__(name, value)
TypeError: __bases__ assignment: 'IPv4Network' object layout differs from '_NoInitSubclass'

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

[1] https://github.com/django/django/blob/102d92fc09849e1a9004dd3f9a14a0ea9ca392cd/tests/model_enums/tests.py#L225-L235

components: Library (Lib)
messages: 384563
nosy: barry, eli.bendersky, ethan.furman, felixxm
priority: normal
severity: normal
status: open
title: Subclassing Enum with ipaddress.IPv4Network/IPv6Network raises TypeError.
type: crash
versions: Python 3.10

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list