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

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

Open
RSAkidinUSA opened this issue Oct 18, 2022 · 1 comment
Open

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

RSAkidinUSA opened this issue Oct 18, 2022 · 1 comment

Comments

@RSAkidinUSA
Copy link

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
Copy link

mojzis commented Oct 27, 2023

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants