2014-01-13 | Paul Boddie | file changeset files shortlog | Added failure tests involving closures. | syspython-as-target |
paul@777 | 1 | #!/usr/bin/env python |
paul@777 | 2 | |
paul@777 | 3 | "Inspired by difflib._mdiff._line_iterator and its from_line variable." |
paul@777 | 4 | |
paul@777 | 5 | def outer(): |
paul@777 | 6 | def inner(x): |
paul@777 | 7 | if x: |
paul@777 | 8 | y = 1 |
paul@777 | 9 | return y |
paul@777 | 10 | y = 2 |
paul@777 | 11 | return inner |
paul@777 | 12 | |
paul@777 | 13 | result_1 = outer()(1) |
paul@777 | 14 | result_2 = outer()(0) # CPython fails with UnboundLocalError in inner |
paul@777 | 15 | |
paul@777 | 16 | # vim: tabstop=4 expandtab shiftwidth=4 |