Skip to content

Custom EnumBase.__new__ broken in 0.5.4. #18

@demberto

Description

@demberto

As referenced in demberto/PyFLP#111, I had been using the EnumBase class like this, since it autogenerates missing members.

class MyEnum(ct.EnumBase):
    def __new__(cls, id: int, ascii: bool = False):
        obj = int.__new__(cls, id)
        obj._value_ = id
        setattr(obj, "ascii", ascii)
        return obj

    Member= (51, True)
    Normal = 52

causes (Python 3.10):

\lib\enum.py:298: in __new__
    enum_member.__init__(*args)
E   TypeError: EnumBase.__init__() takes 2 positional arguments but 3 were given

I tried modifiying the __new__ method to use *args instead but it won't work either:

def __new__(cls, *args: Any):
        if len(args) == 2:
            id, ascii = args
        else:
            (id,) = args
            ascii = False

        obj = int.__new__(cls, id)
        obj._value_ = id
        setattr(obj, "ascii", ascii)
        return obj

results in the same error.

As mentioned in demberto/PyFLP#111 (comment) the change in EnumBase.__init__ seems to have caused this.

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