-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Add base for enumerations (Functional API) #65905
Comments
In enum module the functional API for enum creation has the following signature: so that the numeration always starts with 1. In some cases it is convenient to start numbering from other base, e.g., 0. It would be of great help to add an additional parameter, say start, to make the following call possible: Animal = Enum('Animal', 'ant bee cat dog', start = 0) |
That is certainly nicer than the current idiom: Animal = Enum('Animal', zip('ant bee cat dog'.split(), range(4))) |
Is it really worthwhile to complicate the API for the sake of providing a less flexible solution for rare cases that saves a few keystrokes? |
Playing devil's advocate: The issue is not so much the keystrokes saved as the improvement in reading and understanding what was intended. If you are happy with starting at 1 the idiom is easy to both write, read, and understand; but if you want some other starting number you have to uglify your code with parenthesis, .methods, and add an extra iterator which you have to manually re-sync if you later add another name... I think that is the real issue -- not keystrokes. |
I think that the situation when you want start numbering from 0 is rather common, especially when you need to define bit fields as enumeration or when you need to implement an interface with other languages (e.g., C). |
Looks sensible to me. Except for being name-only, this duplicates the api of enumerate. |
New changeset ec016ba862ba by Ethan Furman in branch 'default': |
New changeset 713ee49ec3ba by Berker Peksag in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: