On Nov 23, 2010, at 05:02 PM, Michael Foord wrote: >> * Enums are not subclassed from ints or strs. They are a distinct data type >> that can be converted to and from ints and strs. EIBTI. > >But if we are to use it *in* the standard library (as opposed to merely >adding a module *to* the standard library) there are backwards compatibility >concerns. Where modules are already using integers for constants then >integers still need to work. Is int(enum_value) enough, or must the enum value actually *be* an int? >One easy way to achieve this is to subclass integer. If we don't do that >(assuming we decide that putting a solution in the standard library is >appropriate) then we'll have to evaluate what we mean by backwards >compatible. If the modules that use the constants aren't to change then >comparing equal to the underlying value is the minimum (so that the original >value can still be used in place of the new named constant). Not sure if >you'd be happy to make that change in flufl.enum. I'm not sure either. In flufl.enum enum_class(i) also works as expected. >> * The typical way to create them is through a simple, but explicit class >> definition. I personally like being explicit about the item values, and >> the assignments are required to make the metaclass work properly, but >> Michael's convenience patch is totally appropriate for cases where you >> don't care, or you want a one-liner. > >If make_enum was to take a set of values to use (as Antoine suggested) I >don't see what's un-explicit about it. When I saw your patch I immediately thought that I could add a default argument that was something like `int_iter`, i.e. an iterator of integers for the values in the string. I suspect YAGNI, which is why I didn't just add it, but I'm not totally opposed to it. -Barry -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-dev/attachments/20101123/b7b918bc/attachment.pgp>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4