Show More
@@ -227,6 +227,35 b' if sys.version_info > (3, 5):' | |||||
227 | else: |
|
227 | else: | |
228 | iprc(cell) |
|
228 | iprc(cell) | |
229 |
|
229 | |||
|
230 | def test_nonlocal(self): | |||
|
231 | # fails if outer scope is not a function scope or if var not defined | |||
|
232 | with self.assertRaises(SyntaxError): | |||
|
233 | iprc("nonlocal x") | |||
|
234 | iprc(""" | |||
|
235 | x = 1 | |||
|
236 | def f(): | |||
|
237 | nonlocal x | |||
|
238 | x = 10000 | |||
|
239 | yield x | |||
|
240 | """) | |||
|
241 | iprc(""" | |||
|
242 | def f(): | |||
|
243 | def g(): | |||
|
244 | nonlocal x | |||
|
245 | x = 10000 | |||
|
246 | yield x | |||
|
247 | """) | |||
|
248 | ||||
|
249 | # works if outer scope is a function scope and var exists | |||
|
250 | iprc(""" | |||
|
251 | def f(): | |||
|
252 | x = 20 | |||
|
253 | def g(): | |||
|
254 | nonlocal x | |||
|
255 | x = 10000 | |||
|
256 | yield x | |||
|
257 | """) | |||
|
258 | ||||
230 |
|
259 | |||
231 | def test_execute(self): |
|
260 | def test_execute(self): | |
232 | iprc(""" |
|
261 | iprc(""" |
General Comments 0
You need to be logged in to leave comments.
Login now