summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-03-01 20:35:45 (GMT)
committerGuido van Rossum <guido@python.org>2001-03-01 20:35:45 (GMT)
commit9aa643cf6909170d31cfff955318ea7317234663 (patch)
treeca7a19dcb75d9bc4af7c1a0737a261c507334128 /Lib
parent7606e4d00ee566471eaaf2b740f2d7406a634146 (diff)
downloadcpython-9aa643cf6909170d31cfff955318ea7317234663.zip
cpython-9aa643cf6909170d31cfff955318ea7317234663.tar.gz
cpython-9aa643cf6909170d31cfff955318ea7317234663.tar.bz2
Test interaction of global and nested scopes -- thanks to Samuele Pedroni.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/output/test_scope1
-rw-r--r--Lib/test/test_scope.py65
2 files changed, 66 insertions, 0 deletions
diff --git a/Lib/test/output/test_scope b/Lib/test/output/test_scope
index 0535e26..5d41e8c 100644
--- a/Lib/test/output/test_scope
+++ b/Lib/test/output/test_scope
@@ -13,3 +13,4 @@ test_scope
12. lambdas
13. UnboundLocal
14. complex definitions
+15. scope of global statements
diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py
index b4c492a..0633b14 100644
--- a/Lib/test/test_scope.py
+++ b/Lib/test/test_scope.py
@@ -318,3 +318,68 @@ def makeAddPair((a, b)):
return addPair
verify(makeAddPair((1, 2))((100, 200)) == (101,202))
+
+print "15. scope of global statements"
+# Examples posted by Samuele Pedroni to python-dev on 3/1/2001
+
+# I
+x = 7
+def f():
+ x = 1
+ def g():
+ global x
+ def i():
+ def h():
+ return x
+ return h()
+ return i()
+ return g()
+verify(f() == 7)
+verify(x == 7)
+
+# II
+x = 7
+def f():
+ x = 1
+ def g():
+ x = 2
+ def i():
+ def h():
+ return x
+ return h()
+ return i()
+ return g()
+verify(f() == 2)
+verify(x == 7)
+
+# III
+x = 7
+def f():
+ x = 1
+ def g():
+ global x
+ x = 2
+ def i():
+ def h():
+ return x
+ return h()
+ return i()
+ return g()
+verify(f() == 2)
+verify(x == 2)
+
+# IV
+x = 7
+def f():
+ x = 3
+ def g():
+ global x
+ x = 2
+ def i():
+ def h():
+ return x
+ return h()
+ return i()
+ return g()
+verify(f() == 2)
+verify(x == 2)