[Python-Dev] assignment expressions: an alternative proposal

Steven D'Aprano steve at pearwood.info
Tue Apr 24 12:57:45 EDT 2018


On Wed, Apr 25, 2018 at 02:42:08AM +1000, Chris Angelico wrote:

> >     from math import *
> >     process(arg, (pi = 1), pi+1)  # allowed

 
> That's not allowed at local scope (at least, it's not allowed at
> function scope - is there any other "local scope" at which it is
> allowed?).

Of course: local just means the current scope, wherever you happen to 
be. Inside a function, local is the current function scope. Inside a 
class body, local is the class body scope. At the top level of the 
module, local means the module scope (and locals() returns the same dict 
as globals()).

If Yury means for this "cannot mask existing variables" to only operate 
inside functions, that means that you can mask existing variables if you 
use assignment expressions in class bodies or top-level module code.


-- 
Steve


More information about the Python-Dev mailing list