Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3.3
Changeset: r72348:7562de248abb
Date: 2014-07-03 23:35 +0200
http://bitbucket.org/pypy/pypy/changeset/7562de248abb/
Log: Apply fix for Cpython Issue15839
diff --git a/pypy/module/__builtin__/descriptor.py
b/pypy/module/__builtin__/descriptor.py
--- a/pypy/module/__builtin__/descriptor.py
+++ b/pypy/module/__builtin__/descriptor.py
@@ -56,14 +56,14 @@
frame = ec.gettopframe()
code = frame.pycode
if not code:
- raise OperationError(space.w_SystemError, space.wrap(
+ raise OperationError(space.w_RuntimeError, space.wrap(
"super(): no code object"))
if code.co_argcount == 0:
- raise OperationError(space.w_SystemError, space.wrap(
+ raise OperationError(space.w_RuntimeError, space.wrap(
"super(): no arguments"))
w_obj = frame.locals_stack_w[0]
if not w_obj:
- raise OperationError(space.w_SystemError, space.wrap(
+ raise OperationError(space.w_RuntimeError, space.wrap(
"super(): arg[0] deleted"))
index = 0
for name in code.co_freevars:
@@ -71,11 +71,15 @@
break
index += 1
else:
- raise OperationError(space.w_SystemError, space.wrap(
+ raise OperationError(space.w_RuntimeError, space.wrap(
"super(): __class__ cell not found"))
# a kind of LOAD_DEREF
cell = frame.cells[len(code.co_cellvars) + index]
- w_starttype = cell.get()
+ try:
+ w_starttype = cell.get()
+ except ValueError:
+ raise OperationError(space.w_RuntimeError, space.wrap(
+ "super(): empty __class__ cell"))
w_obj_or_type = w_obj
if space.is_none(w_obj_or_type):
diff --git a/pypy/module/__builtin__/test/test_descriptor.py
b/pypy/module/__builtin__/test/test_descriptor.py
--- a/pypy/module/__builtin__/test/test_descriptor.py
+++ b/pypy/module/__builtin__/test/test_descriptor.py
@@ -418,3 +418,20 @@
def f():
return __class__
assert X.f() is X
+
+ def test_obscure_super_errors(self):
+ """
+ def f():
+ super()
+ raises(RuntimeError, f)
+ def f(x):
+ del x
+ super()
+ raises(RuntimeError, f, None)
+ class X:
+ def f(x):
+ nonlocal __class__
+ del __class__
+ super()
+ raises(RuntimeError, X().f)
+ """
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit