[New-bugs-announce] [issue32361] global / nonlocal interference : is this a bug, a feature or a design hole ?

Camion report at bugs.python.org
Mon Dec 18 04:59:49 EST 2017


New submission from Camion <camion_spam-pybugs at yahoo.com>:

Hello, 

"PEP 3104 -- Access to Names in Outer Scopes" introduced the keywords "global" and "nonlocal". but didn't make clear (to me) if this behaviour is a bug, an intentional feature, or a design hole which might be considered good or bad. 

I have observed that when the nonlocal keyword gives acces to a grand parent function's variable, the presence in the parent function, of an access to a global variable with the same name, blocks it with a syntax error (SyntaxError: no binding for nonlocal 'a' found).


a = "a : global"
def f():
    a = "a : local to f"
    def g():
#        global a     # uncommenting this line causes a syntax error.
#        a = a+", modified in g"
        def h():
            nonlocal a
            a = a+", modified in h"
        h()
        print (f"in g : a = '{a}'")
    g()
    print (f"in f : a = '{a}'")
f()
print (f"glogal : a = '{a}'")

----------
components: Interpreter Core
messages: 308537
nosy: Camion
priority: normal
severity: normal
status: open
title: global / nonlocal interference : is this a bug, a feature or a design hole ?
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32361>
_______________________________________


More information about the New-bugs-announce mailing list