ethanfurman / aenum

Advanced Enumerations for Python
183 stars 14 forks source link

Not throwing TypeError if `extend_enum` is called without the required number of arguments #33

Open its-wizza opened 1 year ago

its-wizza commented 1 year ago

There is an undefined variable name undefined in _enum.py causing errors if there are not enough arguments given to extend_enum (might be in other cases too but haven't tested)

To recreate:

from aenum import Enum, extend_enum

class MyEnum(Enum, init="var1 var2"):
    pass

extend_enum(MyEnum, "NEW_MEMBER", "my_var1")

Output:

Traceback (most recent call last):
  ...
  File "...\aenum\_enum.py", line 2722, in extend_enum
    new_member.__init__(*args)
  File "...\aenum\_enum.py", line 2203, in __init__
    value = kwds.pop(name, undefined)
NameError: name 'undefined' is not defined

Relevant lines from __init__ of _enum.py:

2200        if len(args) < len(_auto_init_):
2201            remaining_args = _auto_init_[len(args):]
2202            for name in remaining_args:
2203                value = kwds.pop(name, undefined)
2204                if value is undefined:
2205                    raise TypeError('missing value for: %r' % (name, ))
2206                setattr(self, name, value)