diff options
| author | Damien George <damien.p.george@gmail.com> | 2014-04-12 18:20:40 +0100 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2014-04-12 18:20:40 +0100 |
| commit | 6ce427755112c28f8a7efab65d329205d833f623 (patch) | |
| tree | 47b3b292e4472cc15996b745202dd98133e89feb /tests/basics | |
| parent | c2803db010ab575e9387e4eaf2f8090b083b3c5f (diff) | |
py: Make all LOAD_FAST ops check for unbound local.
This is necessary to catch all cases where locals are referenced before
assignment. We still keep the _0, _1, _2 versions of LOAD_FAST to help
reduced the byte code size in RAM.
Addresses issue #457.
Diffstat (limited to 'tests/basics')
| -rw-r--r-- | tests/basics/unboundlocal.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/basics/unboundlocal.py b/tests/basics/unboundlocal.py new file mode 100644 index 000000000..5573da166 --- /dev/null +++ b/tests/basics/unboundlocal.py @@ -0,0 +1,19 @@ +# locals referenced before assignment + +def f1(): + print(x) + x = 1 + +def f2(): + for i in range(0): + print(i) + print(i) + +def check(f): + try: + f() + except NameError: + print("NameError") + +check(f1) +check(f2) |
