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

Add base for enumerations (Functional API) #65905

Closed
dkorchem mannequin opened this issue Jun 10, 2014 · 8 comments
Closed

Add base for enumerations (Functional API) #65905

dkorchem mannequin opened this issue Jun 10, 2014 · 8 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@dkorchem
Copy link
Mannequin

dkorchem mannequin commented Jun 10, 2014

BPO 21706
Nosy @warsaw, @terryjreedy, @ethanfurman

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:

assignee = 'https://github.com/ethanfurman'
closed_at = <Date 2014-09-17.03:36:23.233>
created_at = <Date 2014-06-10.14:33:48.634>
labels = ['type-feature', 'library']
title = 'Add base for enumerations (Functional API)'
updated_at = <Date 2014-09-18.02:22:33.944>
user = 'https://bugs.python.org/dkorchem'

bugs.python.org fields:

activity = <Date 2014-09-18.02:22:33.944>
actor = 'python-dev'
assignee = 'ethan.furman'
closed = True
closed_date = <Date 2014-09-17.03:36:23.233>
closer = 'python-dev'
components = ['Library (Lib)']
creation = <Date 2014-06-10.14:33:48.634>
creator = 'dkorchem'
dependencies = []
files = []
hgrepos = []
issue_num = 21706
keywords = []
message_count = 8.0
messages = ['220169', '220209', '220210', '220212', '220237', '220473', '226975', '227024']
nosy_count = 6.0
nosy_names = ['barry', 'terry.reedy', 'eli.bendersky', 'ethan.furman', 'python-dev', 'dkorchem']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue21706'
versions = ['Python 3.5']

@dkorchem
Copy link
Mannequin Author

dkorchem mannequin commented Jun 10, 2014

In enum module the functional API for enum creation has the following signature:
Enum(value='NewEnumName', names=<...>, *, module='...', qualname='...', type=<mixed-in class>)

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)

@dkorchem dkorchem mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Jun 10, 2014
@ethanfurman
Copy link
Member

ethanfurman commented Jun 10, 2014

That is certainly nicer than the current idiom:

  Animal = Enum('Animal', zip('ant bee cat dog'.split(), range(4)))

@ethanfurman ethanfurman self-assigned this Jun 10, 2014
@elibendersky
Copy link
Mannequin

elibendersky mannequin commented Jun 10, 2014

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?

@ethanfurman
Copy link
Member

ethanfurman commented Jun 10, 2014

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.

@dkorchem
Copy link
Mannequin Author

dkorchem mannequin commented Jun 11, 2014

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).

@terryjreedy
Copy link
Member

terryjreedy commented Jun 13, 2014

Looks sensible to me. Except for being name-only, this duplicates the api of enumerate.

@python-dev
Copy link
Mannequin

python-dev mannequin commented Sep 17, 2014

New changeset ec016ba862ba by Ethan Furman in branch 'default':
Close bpo-21706: add 'start' parameter to functional API
https://hg.python.org/cpython/rev/ec016ba862ba

@python-dev python-dev mannequin closed this as completed Sep 17, 2014
@python-dev
Copy link
Mannequin

python-dev mannequin commented Sep 18, 2014

New changeset 713ee49ec3ba by Berker Peksag in branch 'default':
Issue bpo-21706: Add a versionchanged directive to the functional API docs.
https://hg.python.org/cpython/rev/713ee49ec3ba

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants