[Python-ideas] Quick idea: defining variables from functions that take the variable name
michael.selik at gmail.com
Tue May 31 20:52:58 EDT 2016
On Mon, May 30, 2016 at 11:08 PM Steven D'Aprano <steve at pearwood.info>
> On Mon, May 30, 2016 at 06:16:26PM -0700, Guido van Rossum wrote:
> > T = TypeVar('T')
> > x = Symbol('x')
> > I'm sure this is not a new idea, but so far I've always thought that
> > this is pretty esoteric and the approach here is good enough.
> This comes up a lot and it would be nice to clean it up.
> T = type('T', bases, ns)
> Record = namedtuple('Record', fields)
I'm not enthusiastic about cleaning it up. It feels appropriately awkward.
I don't want my colleagues having too easy a time dynamically creating
types or functions.
You brought up decorators as an example, but I think that was more about
how decorators tend to be used essentially as part of the function
definition. They might dramatically alter the behavior of the function and
yet appear as an afterthought without the decorator syntax. From the PEP
318, "This becomes less readable with longer [functions]". The motivation
said nothing about avoiding typing the function name twice.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas