Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 1 | import unittest |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 2 | from test.support import check_syntax_error, run_unittest |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 3 | |
Jeremy Hylton | cd73836 | 2001-08-07 16:38:19 +0000 | [diff] [blame] | 4 | import warnings |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 5 | warnings.filterwarnings("ignore", r"import \*", SyntaxWarning, "<test string>") |
Guido van Rossum | 796e1e0 | 2001-12-15 18:04:10 +0000 | [diff] [blame] | 6 | warnings.filterwarnings("ignore", r"import \*", SyntaxWarning, "<string>") |
Jeremy Hylton | cd73836 | 2001-08-07 16:38:19 +0000 | [diff] [blame] | 7 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 8 | class ScopeTests(unittest.TestCase): |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 9 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 10 | def testSimpleNesting(self): |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 11 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 12 | def make_adder(x): |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 13 | def adder(y): |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 14 | return x + y |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 15 | return adder |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 16 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 17 | inc = make_adder(1) |
| 18 | plus10 = make_adder(10) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 19 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 20 | self.assertEqual(inc(1), 2) |
| 21 | self.assertEqual(plus10(-2), 8) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 22 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 23 | def testExtraNesting(self): |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 24 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 25 | def make_adder2(x): |
| 26 | def extra(): # check freevars passing through non-use scopes |
| 27 | def adder(y): |
| 28 | return x + y |
| 29 | return adder |
| 30 | return extra() |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 31 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 32 | inc = make_adder2(1) |
| 33 | plus10 = make_adder2(10) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 34 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 35 | self.assertEqual(inc(1), 2) |
| 36 | self.assertEqual(plus10(-2), 8) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 37 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 38 | def testSimpleAndRebinding(self): |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 39 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 40 | def make_adder3(x): |
| 41 | def adder(y): |
| 42 | return x + y |
| 43 | x = x + 1 # check tracking of assignment to x in defining scope |
| 44 | return adder |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 45 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 46 | inc = make_adder3(0) |
| 47 | plus10 = make_adder3(9) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 48 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 49 | self.assertEqual(inc(1), 2) |
| 50 | self.assertEqual(plus10(-2), 8) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 51 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 52 | def testNestingGlobalNoFree(self): |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 53 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 54 | def make_adder4(): # XXX add exta level of indirection |
| 55 | def nest(): |
| 56 | def nest(): |
| 57 | def adder(y): |
| 58 | return global_x + y # check that plain old globals work |
| 59 | return adder |
| 60 | return nest() |
| 61 | return nest() |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 62 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 63 | global_x = 1 |
| 64 | adder = make_adder4() |
| 65 | self.assertEqual(adder(1), 2) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 66 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 67 | global_x = 10 |
| 68 | self.assertEqual(adder(-2), 8) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 69 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 70 | def testNestingThroughClass(self): |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 71 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 72 | def make_adder5(x): |
| 73 | class Adder: |
| 74 | def __call__(self, y): |
| 75 | return x + y |
| 76 | return Adder() |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 77 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 78 | inc = make_adder5(1) |
| 79 | plus10 = make_adder5(10) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 80 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 81 | self.assertEqual(inc(1), 2) |
| 82 | self.assertEqual(plus10(-2), 8) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 83 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 84 | def testNestingPlusFreeRefToGlobal(self): |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 85 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 86 | def make_adder6(x): |
| 87 | global global_nest_x |
| 88 | def adder(y): |
| 89 | return global_nest_x + y |
| 90 | global_nest_x = x |
| 91 | return adder |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 92 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 93 | inc = make_adder6(1) |
| 94 | plus10 = make_adder6(10) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 95 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 96 | self.assertEqual(inc(1), 11) # there's only one global |
| 97 | self.assertEqual(plus10(-2), 8) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 98 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 99 | def testNearestEnclosingScope(self): |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 100 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 101 | def f(x): |
| 102 | def g(y): |
| 103 | x = 42 # check that this masks binding in f() |
| 104 | def h(z): |
| 105 | return x + z |
| 106 | return h |
| 107 | return g(2) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 108 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 109 | test_func = f(10) |
| 110 | self.assertEqual(test_func(5), 47) |
| 111 | |
| 112 | def testMixedFreevarsAndCellvars(self): |
| 113 | |
| 114 | def identity(x): |
| 115 | return x |
| 116 | |
| 117 | def f(x, y, z): |
| 118 | def g(a, b, c): |
| 119 | a = a + x # 3 |
| 120 | def h(): |
| 121 | # z * (4 + 9) |
| 122 | # 3 * 13 |
| 123 | return identity(z * (b + y)) |
| 124 | y = c + z # 9 |
| 125 | return h |
| 126 | return g |
| 127 | |
| 128 | g = f(1, 2, 3) |
| 129 | h = g(2, 4, 6) |
| 130 | self.assertEqual(h(), 39) |
| 131 | |
| 132 | def testFreeVarInMethod(self): |
| 133 | |
| 134 | def test(): |
| 135 | method_and_var = "var" |
| 136 | class Test: |
| 137 | def method_and_var(self): |
| 138 | return "method" |
| 139 | def test(self): |
| 140 | return method_and_var |
| 141 | def actual_global(self): |
| 142 | return str("global") |
| 143 | def str(self): |
| 144 | return str(self) |
| 145 | return Test() |
| 146 | |
| 147 | t = test() |
| 148 | self.assertEqual(t.test(), "var") |
| 149 | self.assertEqual(t.method_and_var(), "method") |
| 150 | self.assertEqual(t.actual_global(), "global") |
| 151 | |
| 152 | method_and_var = "var" |
| 153 | class Test: |
| 154 | # this class is not nested, so the rules are different |
| 155 | def method_and_var(self): |
| 156 | return "method" |
| 157 | def test(self): |
| 158 | return method_and_var |
| 159 | def actual_global(self): |
| 160 | return str("global") |
| 161 | def str(self): |
| 162 | return str(self) |
| 163 | |
| 164 | t = Test() |
| 165 | self.assertEqual(t.test(), "var") |
| 166 | self.assertEqual(t.method_and_var(), "method") |
| 167 | self.assertEqual(t.actual_global(), "global") |
| 168 | |
Amaury Forgeot d'Arc | e670bd4 | 2007-11-24 00:29:24 +0000 | [diff] [blame] | 169 | def testCellIsKwonlyArg(self): |
| 170 | # Issue 1409: Initialisation of a cell value, |
| 171 | # when it comes from a keyword-only parameter |
| 172 | def foo(*, a=17): |
| 173 | def bar(): |
| 174 | return a + 5 |
| 175 | return bar() + 3 |
| 176 | |
| 177 | self.assertEqual(foo(a=42), 50) |
| 178 | self.assertEqual(foo(), 25) |
| 179 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 180 | def testRecursion(self): |
| 181 | |
| 182 | def f(x): |
| 183 | def fact(n): |
| 184 | if n == 0: |
| 185 | return 1 |
| 186 | else: |
| 187 | return n * fact(n - 1) |
| 188 | if x >= 0: |
| 189 | return fact(x) |
| 190 | else: |
Collin Winter | 3add4d7 | 2007-08-29 23:37:32 +0000 | [diff] [blame] | 191 | raise ValueError("x must be >= 0") |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 192 | |
| 193 | self.assertEqual(f(6), 720) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 194 | |
| 195 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 196 | def testUnoptimizedNamespaces(self): |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 197 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 198 | check_syntax_error(self, """\ |
Jeremy Hylton | 5941d19 | 2001-02-27 20:23:58 +0000 | [diff] [blame] | 199 | def unoptimized_clash1(strip): |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 200 | def f(s): |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 201 | from sys import * |
| 202 | return getrefcount(s) # ambiguity: free or local |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 203 | return f |
Jeremy Hylton | 97a0167 | 2001-02-09 22:56:46 +0000 | [diff] [blame] | 204 | """) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 205 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 206 | check_syntax_error(self, """\ |
Jeremy Hylton | 5941d19 | 2001-02-27 20:23:58 +0000 | [diff] [blame] | 207 | def unoptimized_clash2(): |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 208 | from sys import * |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 209 | def f(s): |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 210 | return getrefcount(s) # ambiguity: global or local |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 211 | return f |
Jeremy Hylton | 97a0167 | 2001-02-09 22:56:46 +0000 | [diff] [blame] | 212 | """) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 213 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 214 | check_syntax_error(self, """\ |
Jeremy Hylton | 5941d19 | 2001-02-27 20:23:58 +0000 | [diff] [blame] | 215 | def unoptimized_clash2(): |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 216 | from sys import * |
Jeremy Hylton | 97a0167 | 2001-02-09 22:56:46 +0000 | [diff] [blame] | 217 | def g(): |
| 218 | def f(s): |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 219 | return getrefcount(s) # ambiguity: global or local |
Jeremy Hylton | 97a0167 | 2001-02-09 22:56:46 +0000 | [diff] [blame] | 220 | return f |
| 221 | """) |
| 222 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 223 | check_syntax_error(self, """\ |
Jeremy Hylton | 5941d19 | 2001-02-27 20:23:58 +0000 | [diff] [blame] | 224 | def f(x): |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 225 | def g(): |
| 226 | return x |
Jeremy Hylton | 97a0167 | 2001-02-09 22:56:46 +0000 | [diff] [blame] | 227 | del x # can't del name |
| 228 | """) |
| 229 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 230 | check_syntax_error(self, """\ |
Jeremy Hylton | 5941d19 | 2001-02-27 20:23:58 +0000 | [diff] [blame] | 231 | def f(): |
Jeremy Hylton | 97a0167 | 2001-02-09 22:56:46 +0000 | [diff] [blame] | 232 | def g(): |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 233 | from sys import * |
| 234 | return getrefcount # global or local? |
Tim Peters | 0e6d213 | 2001-02-15 23:56:39 +0000 | [diff] [blame] | 235 | """) |
Jeremy Hylton | 97a0167 | 2001-02-09 22:56:46 +0000 | [diff] [blame] | 236 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 237 | def testLambdas(self): |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 238 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 239 | f1 = lambda x: lambda y: x + y |
| 240 | inc = f1(1) |
| 241 | plus10 = f1(10) |
| 242 | self.assertEqual(inc(1), 2) |
| 243 | self.assertEqual(plus10(5), 15) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 244 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 245 | f2 = lambda x: (lambda : lambda y: x + y)() |
| 246 | inc = f2(1) |
| 247 | plus10 = f2(10) |
| 248 | self.assertEqual(inc(1), 2) |
| 249 | self.assertEqual(plus10(5), 15) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 250 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 251 | f3 = lambda x: lambda y: global_x + y |
| 252 | global_x = 1 |
| 253 | inc = f3(None) |
| 254 | self.assertEqual(inc(2), 3) |
Jeremy Hylton | 4588c78 | 2001-01-25 20:11:23 +0000 | [diff] [blame] | 255 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 256 | f8 = lambda x, y, z: lambda a, b, c: lambda : z * (b + y) |
| 257 | g = f8(1, 2, 3) |
| 258 | h = g(2, 4, 6) |
| 259 | self.assertEqual(h(), 18) |
Jeremy Hylton | de60248 | 2001-02-05 17:35:20 +0000 | [diff] [blame] | 260 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 261 | def testUnboundLocal(self): |
Jeremy Hylton | de60248 | 2001-02-05 17:35:20 +0000 | [diff] [blame] | 262 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 263 | def errorInOuter(): |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 264 | print(y) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 265 | def inner(): |
| 266 | return y |
| 267 | y = 1 |
Jeremy Hylton | de60248 | 2001-02-05 17:35:20 +0000 | [diff] [blame] | 268 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 269 | def errorInInner(): |
| 270 | def inner(): |
| 271 | return y |
| 272 | inner() |
| 273 | y = 1 |
Jeremy Hylton | de60248 | 2001-02-05 17:35:20 +0000 | [diff] [blame] | 274 | |
Alexandre Vassalotti | 6f82818 | 2009-07-21 02:51:58 +0000 | [diff] [blame^] | 275 | self.assertRaises(UnboundLocalError, errorInOuter) |
| 276 | self.assertRaises(NameError, errorInInner) |
Jeremy Hylton | 97a0167 | 2001-02-09 22:56:46 +0000 | [diff] [blame] | 277 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 278 | # test for bug #1501934: incorrect LOAD/STORE_GLOBAL generation |
| 279 | exec(""" |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 280 | global_x = 1 |
| 281 | def f(): |
| 282 | global_x += 1 |
| 283 | try: |
| 284 | f() |
| 285 | except UnboundLocalError: |
| 286 | pass |
| 287 | else: |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 288 | fail('scope of global_x not correctly determined') |
| 289 | """, {'fail': self.fail}) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 290 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 291 | def testComplexDefinitions(self): |
Jeremy Hylton | 97a0167 | 2001-02-09 22:56:46 +0000 | [diff] [blame] | 292 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 293 | def makeReturner(*lst): |
| 294 | def returner(): |
| 295 | return lst |
| 296 | return returner |
Tim Peters | 0e6d213 | 2001-02-15 23:56:39 +0000 | [diff] [blame] | 297 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 298 | self.assertEqual(makeReturner(1,2,3)(), (1,2,3)) |
Tim Peters | 0e6d213 | 2001-02-15 23:56:39 +0000 | [diff] [blame] | 299 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 300 | def makeReturner2(**kwargs): |
| 301 | def returner(): |
| 302 | return kwargs |
| 303 | return returner |
Jeremy Hylton | 97a0167 | 2001-02-09 22:56:46 +0000 | [diff] [blame] | 304 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 305 | self.assertEqual(makeReturner2(a=11)()['a'], 11) |
Jeremy Hylton | 97a0167 | 2001-02-09 22:56:46 +0000 | [diff] [blame] | 306 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 307 | def testScopeOfGlobalStmt(self): |
Guido van Rossum | 9aa643c | 2001-03-01 20:35:45 +0000 | [diff] [blame] | 308 | # Examples posted by Samuele Pedroni to python-dev on 3/1/2001 |
| 309 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 310 | exec("""\ |
Guido van Rossum | 9aa643c | 2001-03-01 20:35:45 +0000 | [diff] [blame] | 311 | # I |
| 312 | x = 7 |
| 313 | def f(): |
| 314 | x = 1 |
| 315 | def g(): |
| 316 | global x |
| 317 | def i(): |
| 318 | def h(): |
| 319 | return x |
| 320 | return h() |
| 321 | return i() |
| 322 | return g() |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 323 | self.assertEqual(f(), 7) |
| 324 | self.assertEqual(x, 7) |
Guido van Rossum | 9aa643c | 2001-03-01 20:35:45 +0000 | [diff] [blame] | 325 | |
| 326 | # II |
| 327 | x = 7 |
| 328 | def f(): |
| 329 | x = 1 |
| 330 | def g(): |
| 331 | x = 2 |
| 332 | def i(): |
| 333 | def h(): |
| 334 | return x |
| 335 | return h() |
| 336 | return i() |
| 337 | return g() |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 338 | self.assertEqual(f(), 2) |
| 339 | self.assertEqual(x, 7) |
Guido van Rossum | 9aa643c | 2001-03-01 20:35:45 +0000 | [diff] [blame] | 340 | |
| 341 | # III |
| 342 | x = 7 |
| 343 | def f(): |
| 344 | x = 1 |
| 345 | def g(): |
| 346 | global x |
| 347 | x = 2 |
| 348 | def i(): |
| 349 | def h(): |
| 350 | return x |
| 351 | return h() |
| 352 | return i() |
| 353 | return g() |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 354 | self.assertEqual(f(), 2) |
| 355 | self.assertEqual(x, 2) |
Guido van Rossum | 9aa643c | 2001-03-01 20:35:45 +0000 | [diff] [blame] | 356 | |
| 357 | # IV |
| 358 | x = 7 |
| 359 | def f(): |
| 360 | x = 3 |
| 361 | def g(): |
| 362 | global x |
| 363 | x = 2 |
| 364 | def i(): |
| 365 | def h(): |
| 366 | return x |
| 367 | return h() |
| 368 | return i() |
| 369 | return g() |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 370 | self.assertEqual(f(), 2) |
| 371 | self.assertEqual(x, 2) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 372 | |
| 373 | # XXX what about global statements in class blocks? |
| 374 | # do they affect methods? |
| 375 | |
| 376 | x = 12 |
| 377 | class Global: |
| 378 | global x |
| 379 | x = 13 |
| 380 | def set(self, val): |
| 381 | x = val |
| 382 | def get(self): |
| 383 | return x |
| 384 | |
| 385 | g = Global() |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 386 | self.assertEqual(g.get(), 13) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 387 | g.set(15) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 388 | self.assertEqual(g.get(), 13) |
| 389 | """) |
Jeremy Hylton | 5b44a67 | 2001-03-13 02:01:12 +0000 | [diff] [blame] | 390 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 391 | def testLeaks(self): |
Jeremy Hylton | 5b44a67 | 2001-03-13 02:01:12 +0000 | [diff] [blame] | 392 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 393 | class Foo: |
| 394 | count = 0 |
Tim Peters | 30edd23 | 2001-03-16 08:29:48 +0000 | [diff] [blame] | 395 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 396 | def __init__(self): |
| 397 | Foo.count += 1 |
Jeremy Hylton | 5b44a67 | 2001-03-13 02:01:12 +0000 | [diff] [blame] | 398 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 399 | def __del__(self): |
| 400 | Foo.count -= 1 |
Jeremy Hylton | 5b44a67 | 2001-03-13 02:01:12 +0000 | [diff] [blame] | 401 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 402 | def f1(): |
| 403 | x = Foo() |
| 404 | def f2(): |
| 405 | return x |
| 406 | f2() |
Tim Peters | 30edd23 | 2001-03-16 08:29:48 +0000 | [diff] [blame] | 407 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 408 | for i in range(100): |
| 409 | f1() |
Jeremy Hylton | 5b44a67 | 2001-03-13 02:01:12 +0000 | [diff] [blame] | 410 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 411 | self.assertEqual(Foo.count, 0) |
Jeremy Hylton | 5c7a251 | 2001-03-21 16:44:39 +0000 | [diff] [blame] | 412 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 413 | def testClassAndGlobal(self): |
Jeremy Hylton | 5c7a251 | 2001-03-21 16:44:39 +0000 | [diff] [blame] | 414 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 415 | exec("""\ |
Jeremy Hylton | 5c7a251 | 2001-03-21 16:44:39 +0000 | [diff] [blame] | 416 | def test(x): |
| 417 | class Foo: |
| 418 | global x |
| 419 | def __call__(self, y): |
| 420 | return x + y |
| 421 | return Foo() |
| 422 | |
| 423 | x = 0 |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 424 | self.assertEqual(test(6)(2), 8) |
Jeremy Hylton | 5c7a251 | 2001-03-21 16:44:39 +0000 | [diff] [blame] | 425 | x = -1 |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 426 | self.assertEqual(test(3)(2), 5) |
Jeremy Hylton | 5c7a251 | 2001-03-21 16:44:39 +0000 | [diff] [blame] | 427 | |
Neil Schemenauer | d403c45 | 2005-10-23 04:24:49 +0000 | [diff] [blame] | 428 | looked_up_by_load_name = False |
| 429 | class X: |
| 430 | # Implicit globals inside classes are be looked up by LOAD_NAME, not |
| 431 | # LOAD_GLOBAL. |
| 432 | locals()['looked_up_by_load_name'] = True |
| 433 | passed = looked_up_by_load_name |
| 434 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 435 | self.assertTrue(X.passed) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 436 | """) |
Neil Schemenauer | d403c45 | 2005-10-23 04:24:49 +0000 | [diff] [blame] | 437 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 438 | def testLocalsFunction(self): |
Jeremy Hylton | 5c7a251 | 2001-03-21 16:44:39 +0000 | [diff] [blame] | 439 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 440 | def f(x): |
| 441 | def g(y): |
| 442 | def h(z): |
| 443 | return y + z |
| 444 | w = x + y |
| 445 | y += 3 |
| 446 | return locals() |
| 447 | return g |
Jeremy Hylton | 5c7a251 | 2001-03-21 16:44:39 +0000 | [diff] [blame] | 448 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 449 | d = f(2)(4) |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 450 | self.assertTrue('h' in d) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 451 | del d['h'] |
| 452 | self.assertEqual(d, {'x': 2, 'y': 7, 'w': 6}) |
Jeremy Hylton | c76770c | 2001-04-13 16:51:46 +0000 | [diff] [blame] | 453 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 454 | def testLocalsClass(self): |
| 455 | # This test verifies that calling locals() does not pollute |
| 456 | # the local namespace of the class with free variables. Old |
| 457 | # versions of Python had a bug, where a free variable being |
| 458 | # passed through a class namespace would be inserted into |
| 459 | # locals() by locals() or exec or a trace function. |
| 460 | # |
| 461 | # The real bug lies in frame code that copies variables |
| 462 | # between fast locals and the locals dict, e.g. when executing |
| 463 | # a trace function. |
| 464 | |
| 465 | def f(x): |
| 466 | class C: |
| 467 | x = 12 |
| 468 | def m(self): |
| 469 | return x |
| 470 | locals() |
| 471 | return C |
| 472 | |
| 473 | self.assertEqual(f(1).x, 12) |
| 474 | |
| 475 | def f(x): |
| 476 | class C: |
| 477 | y = x |
| 478 | def m(self): |
| 479 | return x |
| 480 | z = list(locals()) |
| 481 | return C |
| 482 | |
| 483 | varnames = f(1).z |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 484 | self.assertTrue("x" not in varnames) |
| 485 | self.assertTrue("y" in varnames) |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 486 | |
Georg Brandl | 3dbca81 | 2008-07-23 16:10:53 +0000 | [diff] [blame] | 487 | def testLocalsClass_WithTrace(self): |
| 488 | # Issue23728: after the trace function returns, the locals() |
| 489 | # dictionary is used to update all variables, this used to |
| 490 | # include free variables. But in class statements, free |
| 491 | # variables are not inserted... |
| 492 | import sys |
| 493 | sys.settrace(lambda a,b,c:None) |
| 494 | try: |
| 495 | x = 12 |
| 496 | |
| 497 | class C: |
| 498 | def f(self): |
| 499 | return x |
| 500 | |
| 501 | self.assertEquals(x, 12) # Used to raise UnboundLocalError |
| 502 | finally: |
| 503 | sys.settrace(None) |
| 504 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 505 | def testBoundAndFree(self): |
| 506 | # var is bound and free in class |
Jeremy Hylton | ddc4fd0 | 2001-04-27 02:29:40 +0000 | [diff] [blame] | 507 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 508 | def f(x): |
| 509 | class C: |
| 510 | def m(self): |
| 511 | return x |
| 512 | a = x |
| 513 | return C |
Jeremy Hylton | ddc4fd0 | 2001-04-27 02:29:40 +0000 | [diff] [blame] | 514 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 515 | inst = f(3)() |
| 516 | self.assertEqual(inst.a, inst.m()) |
Jeremy Hylton | 4c88901 | 2001-05-08 04:08:59 +0000 | [diff] [blame] | 517 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 518 | def testInteractionWithTraceFunc(self): |
Jeremy Hylton | 4c88901 | 2001-05-08 04:08:59 +0000 | [diff] [blame] | 519 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 520 | import sys |
| 521 | def tracer(a,b,c): |
| 522 | return tracer |
Jeremy Hylton | 4c88901 | 2001-05-08 04:08:59 +0000 | [diff] [blame] | 523 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 524 | def adaptgetter(name, klass, getter): |
| 525 | kind, des = getter |
| 526 | if kind == 1: # AV happens when stepping from this line to next |
| 527 | if des == "": |
| 528 | des = "_%s__%s" % (klass.__name__, name) |
| 529 | return lambda obj: getattr(obj, des) |
Jeremy Hylton | 4c88901 | 2001-05-08 04:08:59 +0000 | [diff] [blame] | 530 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 531 | class TestClass: |
| 532 | pass |
Jeremy Hylton | 4c88901 | 2001-05-08 04:08:59 +0000 | [diff] [blame] | 533 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 534 | sys.settrace(tracer) |
| 535 | adaptgetter("foo", TestClass, (1, "")) |
| 536 | sys.settrace(None) |
Jeremy Hylton | 5121e7d | 2001-07-30 21:55:29 +0000 | [diff] [blame] | 537 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 538 | self.assertRaises(TypeError, sys.settrace) |
Neal Norwitz | 290d31e | 2002-03-03 15:12:58 +0000 | [diff] [blame] | 539 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 540 | def testEvalExecFreeVars(self): |
Jeremy Hylton | 5121e7d | 2001-07-30 21:55:29 +0000 | [diff] [blame] | 541 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 542 | def f(x): |
| 543 | return lambda: x + 1 |
Jeremy Hylton | 5121e7d | 2001-07-30 21:55:29 +0000 | [diff] [blame] | 544 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 545 | g = f(3) |
Neal Norwitz | 221085d | 2007-02-25 20:55:47 +0000 | [diff] [blame] | 546 | self.assertRaises(TypeError, eval, g.__code__) |
Jeremy Hylton | cd73836 | 2001-08-07 16:38:19 +0000 | [diff] [blame] | 547 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 548 | try: |
Neal Norwitz | 221085d | 2007-02-25 20:55:47 +0000 | [diff] [blame] | 549 | exec(g.__code__, {}) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 550 | except TypeError: |
| 551 | pass |
| 552 | else: |
| 553 | self.fail("exec should have failed, because code contained free vars") |
Jeremy Hylton | ccae8377 | 2001-12-13 19:45:04 +0000 | [diff] [blame] | 554 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 555 | def testListCompLocalVars(self): |
Jeremy Hylton | cf672f1 | 2001-10-18 16:23:11 +0000 | [diff] [blame] | 556 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 557 | try: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 558 | print(bad) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 559 | except NameError: |
| 560 | pass |
| 561 | else: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 562 | print("bad should not be defined") |
Jeremy Hylton | cf672f1 | 2001-10-18 16:23:11 +0000 | [diff] [blame] | 563 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 564 | def x(): |
| 565 | [bad for s in 'a b' for bad in s.split()] |
Jeremy Hylton | cf672f1 | 2001-10-18 16:23:11 +0000 | [diff] [blame] | 566 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 567 | x() |
| 568 | try: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 569 | print(bad) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 570 | except NameError: |
| 571 | pass |
Jeremy Hylton | 954aed8 | 2002-04-20 04:51:39 +0000 | [diff] [blame] | 572 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 573 | def testEvalFreeVars(self): |
Jeremy Hylton | 954aed8 | 2002-04-20 04:51:39 +0000 | [diff] [blame] | 574 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 575 | def f(x): |
| 576 | def g(): |
| 577 | x |
| 578 | eval("x + 1") |
| 579 | return g |
Jeremy Hylton | 954aed8 | 2002-04-20 04:51:39 +0000 | [diff] [blame] | 580 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 581 | f(4)() |
| 582 | |
Christian Heimes | 18c6689 | 2008-02-17 13:31:39 +0000 | [diff] [blame] | 583 | def testFreeingCell(self): |
| 584 | # Test what happens when a finalizer accesses |
| 585 | # the cell where the object was stored. |
| 586 | class Special: |
| 587 | def __del__(self): |
| 588 | nestedcell_get() |
| 589 | |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 590 | def testNonLocalFunction(self): |
| 591 | |
| 592 | def f(x): |
| 593 | def inc(): |
| 594 | nonlocal x |
| 595 | x += 1 |
| 596 | return x |
| 597 | def dec(): |
| 598 | nonlocal x |
| 599 | x -= 1 |
| 600 | return x |
| 601 | return inc, dec |
| 602 | |
| 603 | inc, dec = f(0) |
| 604 | self.assertEqual(inc(), 1) |
| 605 | self.assertEqual(inc(), 2) |
| 606 | self.assertEqual(dec(), 1) |
| 607 | self.assertEqual(dec(), 0) |
| 608 | |
| 609 | def testNonLocalMethod(self): |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 610 | def f(x): |
| 611 | class c: |
| 612 | def inc(self): |
| 613 | nonlocal x |
| 614 | x += 1 |
| 615 | return x |
| 616 | def dec(self): |
| 617 | nonlocal x |
| 618 | x -= 1 |
| 619 | return x |
| 620 | return c() |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 621 | c = f(0) |
| 622 | self.assertEqual(c.inc(), 1) |
| 623 | self.assertEqual(c.inc(), 2) |
| 624 | self.assertEqual(c.dec(), 1) |
| 625 | self.assertEqual(c.dec(), 0) |
| 626 | |
Jeremy Hylton | f37708e | 2009-03-31 15:26:37 +0000 | [diff] [blame] | 627 | def testGlobalInParallelNestedFunctions(self): |
| 628 | # A symbol table bug leaked the global statement from one |
| 629 | # function to other nested functions in the same block. |
| 630 | # This test verifies that a global statement in the first |
| 631 | # function does not affect the second function. |
| 632 | CODE = """def f(): |
| 633 | y = 1 |
| 634 | def g(): |
| 635 | global y |
| 636 | return y |
| 637 | def h(): |
| 638 | return y + 1 |
| 639 | return g, h |
| 640 | y = 9 |
| 641 | g, h = f() |
| 642 | result9 = g() |
| 643 | result2 = h() |
| 644 | """ |
| 645 | local_ns = {} |
| 646 | global_ns = {} |
| 647 | exec(CODE, local_ns, global_ns) |
| 648 | self.assertEqual(2, global_ns["result2"]) |
| 649 | self.assertEqual(9, global_ns["result9"]) |
| 650 | |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 651 | def testNonLocalClass(self): |
| 652 | |
| 653 | def f(x): |
| 654 | class c: |
| 655 | nonlocal x |
| 656 | x += 1 |
| 657 | def get(self): |
| 658 | return x |
| 659 | return c() |
| 660 | |
| 661 | c = f(0) |
| 662 | self.assertEqual(c.get(), 1) |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 663 | self.assertTrue("x" not in c.__class__.__dict__) |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 664 | |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 665 | |
| 666 | def testNonLocalGenerator(self): |
| 667 | |
| 668 | def f(x): |
| 669 | def g(y): |
| 670 | nonlocal x |
| 671 | for i in range(y): |
| 672 | x += 1 |
| 673 | yield x |
| 674 | return g |
| 675 | |
| 676 | g = f(0) |
| 677 | self.assertEqual(list(g(5)), [1, 2, 3, 4, 5]) |
| 678 | |
| 679 | def testNestedNonLocal(self): |
| 680 | |
| 681 | def f(x): |
| 682 | def g(): |
| 683 | nonlocal x |
| 684 | x -= 2 |
| 685 | def h(): |
| 686 | nonlocal x |
| 687 | x += 4 |
| 688 | return x |
| 689 | return h |
| 690 | return g |
| 691 | |
| 692 | g = f(1) |
| 693 | h = g() |
| 694 | self.assertEqual(h(), 3) |
| 695 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 696 | |
| 697 | def test_main(): |
| 698 | run_unittest(ScopeTests) |
| 699 | |
| 700 | if __name__ == '__main__': |
| 701 | test_main() |