[Python-Dev] PEP 435 - ref impl disc 2
Glenn Linderman
v+python at g.nevcal.com
Mon May 6 07:50:24 CEST 2013
On 5/5/2013 9:51 PM, Nick Coghlan wrote:
> On Mon, May 6, 2013 at 12:46 PM, Glenn Linderman <v+python at g.nevcal.com> wrote:
>> Sadly, once the Enums are defined, there is to be no way to subclass them to
>> add functionality, like producing a NamedInt result from operations on them.
> That rule is enforced by the metaclass, so... ;)
Sure. But:
stdlib contains:
Enum (with subclass prohibiting metaclass)
APIs with flags
(assumed, in time) Enums defining the flag values (complete with
enforcement by the metaclass)
user code:
have to recreate all the Enums defining flag values using custom
enum_type metaclass.
Seems like FlagEnum might be a a good thing to invent before
(re-)defining Enums for all the flag values (that's what I'm after in
combining NamedInt and Enum, really).
I suppose that a mere mortal could simply define a subclass of int that
keeps track of expressions during arithmetic... using __name__
attributes of its operands if they exist, and as long as the mere mortal
remembered to use it, it would achieve the same goal. But having that
built in with the flag value definitions would assure that it was
available for everyone, all the time.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130505/7c43df42/attachment.html>
More information about the Python-Dev
mailing list