[Python-ideas] A "local" pseudo-function
Soni L.
fakedme+py at gmail.com
Sun Apr 29 21:35:04 EDT 2018
On 2018-04-29 10:20 PM, Ethan Furman wrote:
> On 04/29/2018 01:20 PM, Tim Peters wrote:
>
>> So, e.g.,
>>
>> """
>> a = 42
>>
>> def showa():
>> print(a)
>>
>> def run():
>> global a
>>
>> local a: # assuming this existed
>> a = 43
>> showa()
>> showa()
>> """
>>
>> would print 43 and then 42. Which makes "local a:" sound senseless on
>> the face of it ;-) "shadow" would be a more descriptive name for what
>> it actually does.
>
> Yeah, "shadow" would be a better name than "local", considering that
> it effectively temporarily changes what other functions see as
> global. Talk about a debugging nightmare! ;)
That ain't shadow. That is dynamic scoping.
Shadowing is something different:
def f():
a = 42
def g():
print(a)
local a:
a = 43
g()
g()
should print "42" both times, *if it's lexically scoped*.
If it's lexically scoped, this is just adding another scope: blocks.
(instead of the smallest possible scope being function scope)
>
> --
> ~Ethan~
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
More information about the Python-ideas
mailing list