Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue21706

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:Add base for enumerations (Functional API)
Type:enhancementStage:resolved
Components:Library (Lib)Versions:Python 3.5
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: ethan.furmanNosy List: barry, dkorchem, eli.bendersky, ethan.furman, python-dev, terry.reedy
Priority:normalKeywords:

Created on2014-06-10 14:33 bydkorchem, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Messages (8)
msg220169 -(view)Author: Dmitry Korchemny (dkorchem)Date: 2014-06-10 14:33
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)
msg220209 -(view)Author: Ethan Furman (ethan.furman)*(Python committer)Date: 2014-06-10 23:15
That is certainly nicer than the current idiom:  Animal = Enum('Animal', zip('ant bee cat dog'.split(), range(4)))
msg220210 -(view)Author: Eli Bendersky (eli.bendersky)*(Python committer)Date: 2014-06-10 23:20
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?
msg220212 -(view)Author: Ethan Furman (ethan.furman)*(Python committer)Date: 2014-06-10 23:34
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.
msg220237 -(view)Author: Dmitry Korchemny (dkorchem)Date: 2014-06-11 06:22
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).
msg220473 -(view)Author: Terry J. Reedy (terry.reedy)*(Python committer)Date: 2014-06-13 17:55
Looks sensible to me. Except for being name-only, this duplicates the api of enumerate.
msg226975 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2014-09-17 03:36
New changesetec016ba862ba by Ethan Furman in branch 'default':Closeissue21706: add 'start' parameter to functional APIhttps://hg.python.org/cpython/rev/ec016ba862ba
msg227024 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2014-09-18 02:22
New changeset713ee49ec3ba by Berker Peksag in branch 'default':Issue#21706: Add a versionchanged directive to the functional API docs.https://hg.python.org/cpython/rev/713ee49ec3ba
History
DateUserActionArgs
2022-04-11 14:58:04adminsetgithub: 65905
2014-09-18 02:22:33python-devsetmessages: +msg227024
2014-09-17 03:36:23python-devsetstatus: open -> closed

nosy: +python-dev
messages: +msg226975

resolution: fixed
stage: resolved
2014-06-13 17:55:58terry.reedysetnosy: +terry.reedy
messages: +msg220473
2014-06-11 06:22:40dkorchemsetmessages: +msg220237
2014-06-10 23:34:22ethan.furmansetmessages: +msg220212
2014-06-10 23:20:26eli.benderskysetmessages: +msg220210
2014-06-10 23:15:57ethan.furmansetassignee:ethan.furman
messages: +msg220209
2014-06-10 14:56:58zach.waresetnosy: +barry,eli.bendersky,ethan.furman
2014-06-10 14:33:48dkorchemcreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp