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

Chris Angelico rosuav at gmail.com
Sat Apr 28 16:20:14 EDT 2018


On Sun, Apr 29, 2018 at 6:04 AM, Ed Kellett <e+python-ideas at kellett.im> wrote:
> 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)
>

Oh, you mean exactly like PEP 572 used to advocate for? :) Can't say
I'd be against that, although I'm not enamoured of the function-like
syntax. But if you remove the function-like syntax and change the
semantics, it isn't exactly Tim's proposal any more. :)

ChrisA


More information about the Python-ideas mailing list