Skip to content

Two apparent unnecessary expressions in Enum.py::EnumType::_find_new_() #103260

Closed as not planned
@sadra-barikbin

Description

@sadra-barikbin

In the statement below, based on past statements, neiter first_enum is None, nor __new__ could reallistically be Enum.__new__.

cpython/Lib/enum.py

Lines 1045 to 1046 in 6abd048

if first_enum is None or __new__ in (Enum.__new__, object.__new__):
use_args = False

first_enum is not None because this has been made sure in _get_mixins_:

cpython/Lib/enum.py

Lines 950 to 951 in 6abd048

if not bases:
return object, Enum

Also __new__ couldn't be Enum.__new__ because the earlier statements do not allow this. The only exception is in this unrealistic scenario:

class AnEnum(Enum):
    __new__ = Enum.__new__

Is this has been the reason that this term is added to the if statement?

By the way in Python3.8 this two expressions don't exist:

cpython/Lib/enum.py

Lines 618 to 619 in 3205d1f

if __new__ is object.__new__:
use_args = False

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions