From 6ce427755112c28f8a7efab65d329205d833f623 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 12 Apr 2014 18:20:40 +0100 Subject: 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. --- tests/basics/unboundlocal.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/basics/unboundlocal.py (limited to 'tests/basics') 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) -- cgit v1.2.3