[Python-ideas] Assignment decorators (Re: The Descriptor Protocol...)
Matthew Woodcraft
matthew at woodcraft.me.uk
Wed Mar 9 23:32:53 CET 2011
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.
-M-
More information about the Python-ideas
mailing list