Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 91cc8fb

Browse files
committed
Fix for bug 4360 "SystemError when method has both super() & closure". Patch
by amaury.forgeotdarc and reviewed by brett.cannon. Also add release notes about the known problems with the email package.
1 parent 2d1ca2d commit 91cc8fb

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

Lib/test/test_super.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ def testSuperInClassMethodsWorking(self):
7070
e = E()
7171
self.assertEqual(e.cm(), (e, (E, (E, (E, 'A'), 'B'), 'C'), 'D'))
7272

73+
def testSuperWithClosure(self):
74+
# Issue4360: super() did not work in a function that
75+
# contains a closure
76+
class E(A):
77+
def f(self):
78+
def nested():
79+
self
80+
return super().f() + 'E'
81+
82+
self.assertEqual(E().f(), 'AE')
83+
7384

7485
def test_main():
7586
support.run_unittest(TestSuper)

Objects/typeobject.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6170,8 +6170,9 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)
61706170
assert(PyUnicode_Check(name));
61716171
if (!PyUnicode_CompareWithASCIIString(name,
61726172
"__class__")) {
6173-
PyObject *cell =
6174-
f->f_localsplus[co->co_nlocals + i];
6173+
Py_ssize_t index = co->co_nlocals +
6174+
PyTuple_GET_SIZE(co->co_cellvars) + i;
6175+
PyObject *cell = f->f_localsplus[index];
61756176
if (cell == NULL || !PyCell_Check(cell)) {
61766177
PyErr_SetString(PyExc_SystemError,
61776178
"super(): bad __class__ cell");

RELNOTES

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ Additional notes for Python 3.0 final
2020
If you need bsddb3 support in Python 3.0, you can find it here:
2121

2222
http://pypi.python.org/pypi/bsddb3
23+
24+
* The email package needs quite a bit of work to make it consistent with
25+
respect to bytes and strings. There have been discussions on
26+
[email protected] about where to go with the email package for 3.0, but
27+
this was not resolved in time for 3.0 final. With enough care though, the
28+
email package in Python 3.0 should be about as usable as it is with Python
29+
2.

0 commit comments

Comments
 (0)