[Python-ideas] Assignment decorators (Re: The Descriptor Protocol...)
Terry Reedy
tjreedy at udel.edu
Wed Mar 9 02:34:08 CET 2011
On 3/8/2011 6:38 PM, Greg Ewing wrote:
> Steven D'Aprano wrote:
>> The feature we're discussing is not an enhanced form of decoration, it
>> is an enhanced form of *assignment*. I think Raymond has got it right,
>> the only appropriate syntax is a variation of the assignment syntax.
>
> I don't entirely agree with that. There are currently two
> existing constructs in Python for creating objects that know
> their own name, 'def' and 'class'. They don't look like forms
> of assignment -- rather, they follow the pattern
>
> <keyword> <name> <some other stuff>
>
> This leads me to think that any further such constructs should
> follow a similar pattern.
There is a third such construct and it follows the same pattern in its
basic form
import name
All are syntactic sugar for
name = makeob('name', *arg, **kwds)
For classes and modules there are visibly such alternatives:
cls = type('cls',bases, classdict)
mod = __import__('mod', ...)
There is also a function in inspect that makes functions.
So your point is correct:
name = makeob('name', ...) # becomes
keywd name ....
but we do not really want a new keyword for every new type of object
with a definition name. Can we do with just one?
--
Terry Jan Reedy
More information about the Python-ideas
mailing list