"Data" vs. "Non-data" Descriptors in PEP 252, and "once" attributes
Martin von Loewis
loewis at informatik.hu-berlin.de
Mon Feb 25 05:40:22 EST 2002
Phillip J. Eby <pje at telecommunity.com> writes:
> Interestingly, this does *not* work if you try to do something similar
> with the built-in 'property' type.
I don't find this surprising. The builtin property type has a fixed
meaning for its constructor argument: they are callables, and they are
called on each access. How did you mean to implement your "once"
properties with it?
> Does anyone know if this usage is safe for future Python versions?
That is the intention. There may be a different syntax in addition to
the one you are using now, which may allow you to write
class aThing(object):
def anAttr(self) [once]:
print "computing anAttr"
return 100*100
The idea is that at the end of the function definition, once is lookup
up and called with the function that was just defined; whatever it
returns is then taken as the value of anAttr inside aThing.
> Operationally, it seems it would be hard to change any of this in a way
> that would break my "once" examples without also breaking lots of other
> things. But the PEP doesn't really give an official way to create either
> a data or non-data descriptor; it just says what the current
> implementation does. Hence my concern.
Nobody can tell the future with certainty. If you think that certain
wording would tighten the PEP to make you feel more safe, just submit
a patch for the PEP to SF.
Regards,
Martin
More information about the Python-list
mailing list