[Python-ideas] A user story concerning things knowing their own names

Robert Kern robert.kern at gmail.com
Fri Mar 18 17:44:18 CET 2011


On 3/17/11 11:18 PM, Guido van Rossum wrote:

> At the same time, it seems that there aren't a lot of specific
> examples besides namedtuple (which seems to cause lots of emotions and
> is I think best left alone) and Greg's overridable_property. So,
> unless we can come up with a really nice way (either syntactical or
> perhaps through a magic builtin) to give functions like
> overridable_property() access to the LHS name, and find more use
> cases, I don't see this happening.

A sizable portion of Traits needs the name information.

   http://pypi.python.org/pypi/Traits

As I explained elsewhere, we currently implement this by overriding 
__getattribute__ to implement a descriptor-like protocol that passes along the 
name to the trait object rather than storing it on the trait object itself, but 
we could re-engineer Traits make do with Ian's __addtoclass__ proposal. Being 
able to use plain descriptors would allow us to rewrite Traits to avoid our 
current C-implemented base class, which would let us interoperate with other 
frameworks better.

I can list all of the specific features of Traits that makes use of this 
information if you like.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-ideas mailing list