[Python-ideas] Assignment decorators (Re: The Descriptor Protocol...)
MRAB
python at mrabarnett.plus.com
Thu Mar 10 00:12:20 CET 2011
On 09/03/2011 22:32, Matthew Woodcraft wrote:
> On 2011年03月09日 01:34, Terry Reedy wrote:
>> 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?
>> Thinking along those lines suggests
>> def(CharField) foo(size=10, nullable=False)
>> as sugar for
>> foo = CharField(size=10, nullable=False, __name__='foo')
>>> This seems quite a good parallel to class definitions, though less close
> to function definitions and import statements.
>In class and function definitions the name immediately follows the
keyword. To me it would be clearer to write it:
def foo = CharField(size=10, nullable=False)
or similar.
More information about the Python-ideas
mailing list