From a562329af4c842d00d3e93767c4576f91849de15 2018-10-09 22:39:09 From: felixzhuologist Date: 2018-10-09 22:39:09 Subject: [PATCH] add test for nonlocal case --- diff --git a/IPython/core/tests/test_async_helpers.py b/IPython/core/tests/test_async_helpers.py index 6bf64e2..20ad3d0 100644 --- a/IPython/core/tests/test_async_helpers.py +++ b/IPython/core/tests/test_async_helpers.py @@ -227,6 +227,35 @@ if sys.version_info > (3, 5): else: iprc(cell) + def test_nonlocal(self): + # fails if outer scope is not a function scope or if var not defined + with self.assertRaises(SyntaxError): + iprc("nonlocal x") + iprc(""" + x = 1 + def f(): + nonlocal x + x = 10000 + yield x + """) + iprc(""" + def f(): + def g(): + nonlocal x + x = 10000 + yield x + """) + + # works if outer scope is a function scope and var exists + iprc(""" + def f(): + x = 20 + def g(): + nonlocal x + x = 10000 + yield x + """) + def test_execute(self): iprc("""