[Python-ideas] Quick idea: defining variables from functions that take the variable name

Steven D'Aprano steve at pearwood.info
Wed Jun 1 12:14:31 EDT 2016


On Tue, May 31, 2016 at 01:09:05PM -0300, Alan Cristhian wrote:
> > The fundamental use-case here is "any object that needs to know its own
> > name". Most objects need more than just a name.
> 
> A more general solution could be:
>
>     def x, y, z as <expression>
> 
> Where <expression> should return a callable that accept only one argument.

You should consider how your suggestion will work with the existing 
use-cases already shown.

We've got two dead-simple use-cases to consider. If this proposal makes 
those use-cases harder than the status quo, then this proposal is dead 
in the water. Nobody is going to use it.


# Status quo.
T = Typevar('T')
x = sympy.Symbol('x')

# My proposal.
T -> Typevar()
x -> sympy.Symbol()


# Your proposal.
def T as (lambda: Typevar)()
def x as (lambda: sympy.Symbol)()


You specify that the expression on the right must return a function that 
takes one variable, so you cannot use Typevar or Symbol directly. You 
have to call a function that returns the function you actually want.

Syntactic sugar is supposed to make things easier, not harder.



-- 
Steve


More information about the Python-ideas mailing list