Skip to content
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

Subclassing Enum with ipaddress.IPv4Network/IPv6Network raises TypeError. #87017

Closed
felixxm mannequin opened this issue Jan 7, 2021 · 5 comments
Closed

Subclassing Enum with ipaddress.IPv4Network/IPv6Network raises TypeError. #87017

felixxm mannequin opened this issue Jan 7, 2021 · 5 comments
Assignees
Labels
3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@felixxm
Copy link
Mannequin

felixxm mannequin commented Jan 7, 2021

BPO 42851
Nosy @warsaw, @ethanfurman, @felixxm
PRs
  • bpo-42851: [Enum] remove brittle __init_subclass__ support #24154
  • [3.9] bpo-42851: [Enum] remove brittle __init_subclass__ support (GH-24154) #24155
  • 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 2021-01-08.18:13:45.425>
    created_at = <Date 2021-01-07.06:39:43.166>
    labels = ['3.10', 'library', '3.9', 'type-crash']
    title = 'Subclassing Enum with ipaddress.IPv4Network/IPv6Network raises TypeError.'
    updated_at = <Date 2021-01-08.18:13:45.424>
    user = 'https://github.com/felixxm'

    bugs.python.org fields:

    activity = <Date 2021-01-08.18:13:45.424>
    actor = 'ethan.furman'
    assignee = 'ethan.furman'
    closed = True
    closed_date = <Date 2021-01-08.18:13:45.425>
    closer = 'ethan.furman'
    components = ['Library (Lib)']
    creation = <Date 2021-01-07.06:39:43.166>
    creator = 'felixxm'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42851
    keywords = ['patch']
    message_count = 5.0
    messages = ['384563', '384591', '384605', '384608', '384639']
    nosy_count = 4.0
    nosy_names = ['barry', 'eli.bendersky', 'ethan.furman', 'felixxm']
    pr_nums = ['24154', '24155']
    priority = 'high'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue42851'
    versions = ['Python 3.9', 'Python 3.10']

    @felixxm
    Copy link
    Mannequin Author

    felixxm mannequin commented Jan 7, 2021

    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

    @felixxm felixxm mannequin added 3.10 only security fixes stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Jan 7, 2021
    @ethanfurman
    Copy link
    Member

    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.

    @ethanfurman
    Copy link
    Member

    New changeset a581a86 by Ethan Furman in branch 'master':
    bpo-42851: [Enum] remove brittle __init_subclass__ support (GH-24154)
    a581a86

    @ethanfurman
    Copy link
    Member

    New changeset 9ab4dd4 by Ethan Furman in branch '3.9':
    [3.9] bpo-42851: [Enum] remove brittle __init_subclass__ support (GH-24154) (GH-24155)
    9ab4dd4

    @felixxm
    Copy link
    Mannequin Author

    felixxm mannequin commented Jan 8, 2021

    Ethan, Thanks for the patch.

    @ethanfurman ethanfurman added the 3.9 only security fixes label Jan 8, 2021
    @ethanfurman ethanfurman added the 3.9 only security fixes label Jan 8, 2021
    @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.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant