[Python-ideas] Assignment decorators (Re: The Descriptor Protocol...)
jimjjewett at gmail.com
Wed Mar 9 03:10:41 CET 2011
On Tue, Mar 8, 2011 at 6:50 PM, Larry Hastings <larry at hastings.org> wrote:
> On 03/08/2011 06:38 PM, Greg Ewing wrote:
>> existing constructs in Python for creating objects that know
>> their own name, 'def' and 'class'. ...
>> <keyword> <name> <some other stuff>
>... criteria that makes a good keyword (short,
> meaningful, in this case a noun) also makes for a
> good identifier.
It doesn't have to be a noun; the documentation already refers to
binding names, so ...
bind x = whatever(..., __name__=x)
Though I personally suspect that if the name of the variable is
needed, it is really a slot rather than a discardable name, and it
really *should* be a slightly different object -- a decorable pointer
instead of just a pointer.
boundname x = whatever(..., __name__=x)
Obviously, the interpreter writes the __name__=x for you, or the
proposal loses value.
Note that once there is such an object (type boundname) decorators do
make sense again...
boundname x = "initval"
More information about the Python-ideas