On Apr 25, 2013, at 02:25 PM, Eli Bendersky wrote: >I think it's important to stress what this syntax is actually going to be >used for. No one (I hope) is actually going to write Animals(1) or >Animals[1]. They will write Animals.ant - this is what enums are for in the >first place! The way I see it, this syntax is for enabling *programmatic >access* - if you pull the value from a DB and want to convert it to an >actual enum value, etc. So do we really need to have two syntaxes for this?
Excellent point, and no, we don't :). >The call syntax already has other uses, and it's weird because: > >Enum(....) -> Creates new enums >Animals(....) --> accesses values ?! This is contradictory > >Animals[...] to serve as a by-value lookup makes sense, though. I think so too. :) Note that I discovered that the same two-value call syntax on Enum can be used on the derived classes. It's exactly the same as using subclassing syntax to extend an existing enum. E.g. >>> class A(Enum): ... a = 1 ... b = 2 ... c = 3 ... >>> class B(A): ... d = 4 ... e = 5 ... >>> B.a is A.a True >>> X = Enum('X', 'a b c') >>> Y = X('Y', (('d', 4), ('e', 5))) >>> Y.a is X.a True That's a nice symmetry. -Barry
signature.asc
Description: PGP signature
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com