[Python-Dev] Enum Eccentricities
ncoghlan at gmail.com
Tue Sep 24 01:25:10 CEST 2013
On 24 Sep 2013 08:09, "Greg Ewing" <greg.ewing at canterbury.ac.nz> wrote:
> Steven D'Aprano wrote:
>> It might not be a rule, but it's certainly the norm. I reckon that class
attributes that aren't accessible from the instance are significantly more
surprising than Color.red.blue.
> There are really two different kinds of things that we
> refer to as "class attributes". One is things that really
> are attributes of the class itself, and the other is
> things that are meant to serve as default or shared
> instance attributes.
> The confusion comes in because we use the same terminology
> for both, and because Python doesn't provide any straightforward
> way of creating user-defined class-only attributes,
Using @property in a metaclass definition isn't *that* complicated :)
(says the guy who helps maintain the type system)
> shared attributes tend to get abused for that purpose.
> Then when someone comes along and creates a true
> class-only attribute, people get all surprised and
> complain about it.
One of the interesting aspects of adding Enum has been the subtle
descriptor handling bugs it has uncovered in the inspect module :)
> They shouldn't, IMO.
There's a helper for Enum's descriptors that will probably be exposed
through the types module in the next 3.4 alpha (tentative name is
types.DynamicClassAttribute). It's the inverse, though - it throws
AttributeError when looked up on the *class* in order to trigger
__getattr__ on the metaclass.
> Python-Dev mailing list
> Python-Dev at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev