[Python-Dev] constant/enum type in stdlib

Michael Foord fuzzyman at voidspace.org.uk
Wed Nov 24 01:41:37 CET 2010


On 23/11/2010 21:15, Antoine Pitrou wrote:
> Le mardi 23 novembre 2010 à 16:10 -0500, Glyph Lefkowitz a écrit :
>> On Nov 23, 2010, at 10:01 AM, Antoine Pitrou wrote:
>>
>>> Well, it is easy to assign range(N) to a tuple of names when
>>> desired. I
>>> don't think an automatically-enumerating constant generator is
>>> needed.
>> I don't think that numerical enumerations are the only kind of
>> constants we're talking about.  Others have already mentioned strings.
>> Also, see<http://tm.tl/4671>  for some other use-cases.  Since this
>> isn't coming to 2.x, we're probably going to do our own thing anyway
>> (unless it turns out that flufl.enum is so great that we want to add
>> another dependency...) but I'm hoping that the outcome of this
>> discussion will point to something we can be compatible with.
> I think that asking for too many features would get in the way, and also
> make the API quite un-Pythonic. If you want your values to be e.g.
> OR'able, just choose your values wisely ;)
>

Well, the point of an OR'able flag is that the result shows the OR'd 
values in the repr. Raymond suggests using a set of strings where you 
need flag constants. For new apis (so no backwards compatibility 
constraints) where you don't need to use integers (i.e. not wrapping a C 
library) that's a great suggestion:

     flags = {'FOO', 'BAR'}

Michael
> Regards
>
> Antoine.
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk


-- 

http://www.voidspace.org.uk/

READ CAREFULLY. By accepting and reading this email you agree,
on behalf of your employer, to release me from all obligations
and waivers arising from any and all NON-NEGOTIATED agreements,
licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap,
confidentiality, non-disclosure, non-compete and acceptable use
policies (”BOGUS AGREEMENTS”) that I have entered into with your
employer, its partners, licensors, agents and assigns, in
perpetuity, without prejudice to my ongoing rights and privileges.
You further represent that you have the authority to release me
from any BOGUS AGREEMENTS on behalf of your employer.



More information about the Python-Dev mailing list