[Python-ideas] A "local" pseudo-function

Ed Kellett e+python-ideas at kellett.im
Sat Apr 28 16:04:00 EDT 2018


On 2018-04-28 18:36, Chris Angelico wrote:
> This makes reasonable sense. The parentheses completely enclose the
> local scope. It's compiler magic, and you cannot explain it as a
> function call, but it makes intuitive sense. But the same thing inside
> the if header itself would be much weirder. I'm actually not even sure
> what it would do. And you've clearly shown that the local() call can
> be anywhere inside the condition, based on these examples:

What if the names persist until the end of the statement? That covers if
(where the statement lasts until the end of the if...elif...else block)
and regular expressions, though it does introduce a potentially annoying
shadowing thing:

>>> x = 2
>>> (local(x=4, x + 1), x)
(5,4)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180428/72eb23d7/attachment.sig>


More information about the Python-ideas mailing list