diff options
author | Benjamin Peterson <benjamin@python.org> | 2013-04-30 13:41:40 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2013-04-30 13:41:40 (GMT) |
commit | 3b0431dc6019d2f9ffa9adcaa78ddd3f7b76a2f5 (patch) | |
tree | 7f98ecba2e560776b91856eb74487c26c73d5d0d /Lib | |
parent | f256f5f3ebf6574a2708cfea36d857846893e71f (diff) | |
download | cpython-3b0431dc6019d2f9ffa9adcaa78ddd3f7b76a2f5.zip cpython-3b0431dc6019d2f9ffa9adcaa78ddd3f7b76a2f5.tar.gz cpython-3b0431dc6019d2f9ffa9adcaa78ddd3f7b76a2f5.tar.bz2 |
check local class namespace before reaching for cells (closes #17853)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/importlib/_bootstrap.py | 4 | ||||
-rw-r--r-- | Lib/opcode.py | 3 | ||||
-rw-r--r-- | Lib/test/test_scope.py | 13 |
3 files changed, 19 insertions, 1 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index 77c14bc..1a046c5 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -388,12 +388,14 @@ def _call_with_frames_removed(f, *args, **kwds): # Python 3.3a4 3230 (revert changes to implicit __class__ closure) # Python 3.4a1 3250 (evaluate positional default arguments before # keyword-only defaults) +# Python 3.4a1 3260 (add LOAD_CLASSDEREF; allow locals of class to override +# free vars) # # MAGIC must change whenever the bytecode emitted by the compiler may no # longer be understood by older implementations of the eval loop (usually # due to the addition of new opcodes). -_MAGIC_BYTES = (3250).to_bytes(2, 'little') + b'\r\n' +_MAGIC_BYTES = (3260).to_bytes(2, 'little') + b'\r\n' _RAW_MAGIC_NUMBER = int.from_bytes(_MAGIC_BYTES, 'little') _PYCACHE = '__pycache__' diff --git a/Lib/opcode.py b/Lib/opcode.py index a639fe3..4657b86 100644 --- a/Lib/opcode.py +++ b/Lib/opcode.py @@ -179,6 +179,9 @@ def_op('LIST_APPEND', 145) def_op('SET_ADD', 146) def_op('MAP_ADD', 147) +def_op('LOAD_CLASSDEREF', 148) +hasfree.append(148) + def_op('EXTENDED_ARG', 144) EXTENDED_ARG = 144 diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py index 129a18a..f4ed244 100644 --- a/Lib/test/test_scope.py +++ b/Lib/test/test_scope.py @@ -714,6 +714,19 @@ class ScopeTests(unittest.TestCase): global a + def testClassNamespaceOverridesClosure(self): + # See #17853. + x = 42 + class X: + locals()["x"] = 43 + y = x + self.assertEqual(X.y, 43) + class X: + locals()["x"] = 43 + del x + self.assertFalse(hasattr(X, "x")) + self.assertEqual(x, 42) + def test_main(): run_unittest(ScopeTests) |