[Python-ideas] names as objects [was: The Descriptor Protocol...]
Jim Jewett
jimjjewett at gmail.com
Fri Mar 4 21:56:49 CET 2011
On Wed, Mar 2, 2011 at 4:05 AM, Martin Chilvers
<martin.chilvers at gmail.com> wrote:
...
> def __getattribute__(self, key):
> "Emulate type_getattro() in Objects/typeobject.c"
> v = object.__getattribute__(self, key)
> if hasattr(v, '__get__'):
> return v.__get__(None, self)
> return v
...
> why isn't the 'key' argument passed through
> to the '__get__' (and similarly, '__set__') methods?
...
> class Person(object):
> name = Str()
This thread (and child threads) raised similar examples, such as named
properties, where
varname=something('varname', ...)
Is this really *only* about names, or are there other ways we might
want to decorate an attribute? I assume that examples like Str()
suggest a desire for more information -- and possibly more persistent
information -- than just the name.
Would your use cases (and the similar cases in the attribute
decoration thread) be solved by making the name bindings themselves
into something more than pointers?
Using "<-" for "the name, not the value", would the following be helpful?
class Foo:
x=47
x<-type = int # But is this enforced? Same questions
# as with decorators.
print (x<-__name__) # __name__ probably is a little magic
-jJ
More information about the Python-ideas
mailing list