[Python-ideas] "Assignment expression" with function call-alike syntax

Masayuki YAMAMOTO ma3yuki.8mamo10 at gmail.com
Wed May 23 07:19:35 EDT 2018


2018-05-23 6:32 GMT+09:00 Kirill Balunov <kirillbalunov at gmail.com>:

> Just one more variation on "assignment exression" syntax to make the list
> more complete :) Sorry, if something similar has already been suggested.
> The idea is to use function's call-like syntax in the from: `this( name =
> expr )`. I'm not sure that such idea will find its supporters and whether
> it is possible to implement it in a general way, but nevertheless. Below is
> a half- and slow-working prototype and some silly examples just for the
> sake of feeling the idea:
>
> import sys
> import ctypes
>
> def this(**assign):
>     assert len(assign) == 1
>     [(name, value)] = assign.items()
>     frame = sys._getframe(1)
>     frame.f_locals[name] = value
>     ctypes.pythonapi.PyFrame_LocalsToFast(ctypes.py_object(frame),
>                                           ctypes.c_int(0))
>     return value
>
> FYI, I found a package [*] which binds a value by function keyword (I'm
not the author). Note that the package writes a value in the global (or
raise an error if the name already exists in local) unlike your idea.

[*] https://pypi.org/project/let3/

--
Masayuki
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180523/c98a4ada/attachment.html>


More information about the Python-ideas mailing list