[Python-Dev] Enum Eccentricities

Nick Coghlan 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)

> so
> 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.

Cheers,
Nick.

>
> --
> Greg
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130924/155de6aa/attachment.html>


More information about the Python-Dev mailing list