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

Steven D'Aprano steve at pearwood.info
Sat Apr 28 05:33:34 EDT 2018


On Fri, Apr 27, 2018 at 09:37:53PM -0500, Tim Peters wrote:
> A brain dump, inspired by various use cases that came up during the
> binding expression discussions.
> 
> Idea:  introduce a "local" pseudo-function to capture the idea of
> initialized names with limited scope.
[...]

Chris' PEP 572 started off with the concept that binding expressions 
would create a "sub-local" scope, below function locals. After some 
debate on Python-Ideas, Chris, Nick and Guido took the discussion off 
list and decided to drop the sub-local scope idea as confusing and hard 
to implement.

But the biggest problem is that this re-introduces exactly the same 
awful C mistake that := was chosen to avoid. Which of the following two 
contains the typo?

    local(spam=expression, eggs=expression, cheese = spam+eggs)

    local(spam=expression, eggs=expression, cheese == spam+eggs)


I have other objections, but I'll leave them for now, since I think 
these two alone are fatal. Once you drop those two flaws, you're 
basically left with PEP 572 :-)



-- 
Steve


More information about the Python-ideas mailing list