This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Camion
Recipients Camion
Date 2017-12-18.09:59:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1513591189.6.0.213398074469.issue32361@psf.upfronthosting.co.za>
In-reply-to
Content
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}'")
History
Date User Action Args
2017-12-18 09:59:49Camionsetrecipients: + Camion
2017-12-18 09:59:49Camionsetmessageid: <1513591189.6.0.213398074469.issue32361@psf.upfronthosting.co.za>
2017-12-18 09:59:49Camionlinkissue32361 messages
2017-12-18 09:59:49Camioncreate