New submission from Camion <camion_spam-pyb...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue32361>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to