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

Michel Desmoulin desmoulinmichel at gmail.com
Tue Jun 7 05:24:06 EDT 2016


So for namedtuple:

foo = namedtuple('foo', ['a', 'b'])

Would become:

@recordbinding
foo = namedtuple(['a', 'b'])

?

This doesn't look like an improvement.


Le 07/06/2016 00:32, Barry Warsaw a écrit :
> On Jun 01, 2016, at 03:53 PM, M.-A. Lemburg wrote:
>
>> This could be done via a decorator:
>>
>>     @recordbinding
>>     x = obj
>>
>> to result in the compiler generating the following code:
>>
>>     x = obj
>>     obj.recordbinding('x', 2)
>
> I like the idea of using a decorator because it's familiar syntax and we all
> already (think we) know what it means.  However, in this case, wouldn't
>
>      @recordbinding
>      x = obj
>
> translate to
>
>      x = obj
>      recordbinding(x)
>
> ?
>
> The way you've written it, obj must be a type that implements the
> recordbinding method, but that's not what I'd expect.
>
> Cheers,
> -Barry
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>


More information about the Python-ideas mailing list