# HG changeset patch # User Paul Boddie # Date 1473364580 -7200 # Node ID bba45312185d2eeef6c7cf89aef7fa178d752873 # Parent 7aeee828e698ecfa72410540c5380820f64ef9ad Changed nested scope tests to work without implicit name propagation. diff -r 7aeee828e698 -r bba45312185d tests/nested.py --- a/tests/nested.py Thu Sep 08 21:36:58 2016 +0200 +++ b/tests/nested.py Thu Sep 08 21:56:20 2016 +0200 @@ -1,8 +1,8 @@ a = 4 def f(x): - def g(y): - def h(z): + def g(y, x=x): + def h(z, x=x, y=y): return x, y, z, a return h return g diff -r 7aeee828e698 -r bba45312185d tests/nested_bad.py --- a/tests/nested_bad.py Thu Sep 08 21:36:58 2016 +0200 +++ b/tests/nested_bad.py Thu Sep 08 21:56:20 2016 +0200 @@ -1,7 +1,7 @@ def f(x): - def g(y): + def g(y, x=x): while 1: - def h(z): + def h(z, x=x, y=y): return x, y, z, a a = 4 # not available for h, available in Python return h diff -r 7aeee828e698 -r bba45312185d tests/nested_bad_python.py --- a/tests/nested_bad_python.py Thu Sep 08 21:36:58 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -a = 4 - -def f(x): - def g(): - def h(z): - return x, y, z, a - h(3) # NameError in Python - y = 2 # not available for h, detected during inspection - return h - return g - -result = f(1)()(3) -assert result == (1, 2, 3, 4) diff -r 7aeee828e698 -r bba45312185d tests/nested_lambda.py --- a/tests/nested_lambda.py Thu Sep 08 21:36:58 2016 +0200 +++ b/tests/nested_lambda.py Thu Sep 08 21:56:20 2016 +0200 @@ -1,7 +1,7 @@ a = 4 def f(x): - g = lambda y: lambda z: (x, y, z, a) + g = lambda y, x=x: lambda z, x=x, y=y: (x, y, z, a) return g result = f(1)(2)(3) diff -r 7aeee828e698 -r bba45312185d tests/nested_mixed.py --- a/tests/nested_mixed.py Thu Sep 08 21:36:58 2016 +0200 +++ b/tests/nested_mixed.py Thu Sep 08 21:56:20 2016 +0200 @@ -1,11 +1,11 @@ a = 4 def f(x): - def g(y): - def h(y, z): - return x, y, z, a # parameter y overrides outer scope + def g(y, x=x): + def h(a, z, x=x, y=y): + return x, y, z, a # parameter a overrides global scope return h return g result = f(1)(2)(5, 3) -assert result == (1, 5, 3, 4) +assert result == (1, 2, 3, 5) diff -r 7aeee828e698 -r bba45312185d tests/nested_mixed_names.py --- a/tests/nested_mixed_names.py Thu Sep 08 21:36:58 2016 +0200 +++ b/tests/nested_mixed_names.py Thu Sep 08 21:56:20 2016 +0200 @@ -10,7 +10,7 @@ def f(x): x.c() - def g(y): # x introduced as default here + def g(y, x=x): # x must be introduced as default here if y: x = D() return x.d(), y, a # UnboundLocalError in Python (if y is a false value) diff -r 7aeee828e698 -r bba45312185d tests/nested_value_changed.py --- a/tests/nested_value_changed.py Thu Sep 08 21:36:58 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -a = 4 - -def f(x): - def g(): - y = 2 # used to initialise h - def h(z): - return x, y, z, a - y = 5 # Python uses this value directly from g in h - return h - return g - -result = f(1)()(3) -assert result == (1, 2, 3, 4) # (1, 5, 3, 4) in Python