ethanfurman / aenum

Advanced Enumerations for Python
179 stars 13 forks source link

successive auto()'s not functioning correctly with _init_ #24

Open RSAkidinUSA opened 1 year ago

RSAkidinUSA commented 1 year ago

If auto has non-value arguments and is called successively all following calls will be set to the previous value. e.g.

from aenum import Enum, auto
class A(Enum):
    _init_ = 'value comment'
    a = 1, 'comment for a'
    b = auto('comment for b')
    c = auto('comment for c')

In the above A.a and A.b are unique, but A.b == A.c - but if you do the following, everything is fine:

from aenum import Enum, auto
class A(Enum):
    _init_ = 'value comment'
    a = 1, 'comment for a'
    b = auto('comment for b')
    d = 3, 'comment for d'
    c = auto('comment for c')

Also, if in above you set d = 2, 'comment for d', A.c is fine, but A.d == A.b.

Somewhat related, it would be nice to be able to write a custom function to handle empty auto's / provide default arguments for init.

mojzis commented 10 months ago

I think what you want to do might be this ?

from aenum import Enum, auto
class A(Enum):
    _init_ = 'value comment'
    a = 1, 'comment for a'
    b = auto(), 'comment for b'
    c = auto(), 'comment for c'

seems to work fine ? image

I actually came to this issue looking for a solution of your last sentence. If I am getting it right, this might be it :)

from aenum import Enum, AddValue

class tst(Enum):
    def _generate_next_value_(name, start, count, last, *args, **kwargs):
        return (name,args[0])
    _settings_ = AddValue
    _init_ = "value other"

    FOO = "hohoho"