New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SystemError when method has both super() & closure #48610
Comments
################################
# super_closure.py
class A(object):
def foo(self):
return super()
# remove the closure below
# & SystemError goes away ???
lambda: self
A().foo()
################################ when run on 3.0rc1 & 3.0rc2: hpc-login2 3 ~/work/py3to2: python3.0 super_closure.py
Traceback (most recent call last):
File "super_closure.py", line 9, in <module>
A().foo()
File "super_closure.py", line 5, in foo
return super()
SystemError: super(): __class__ is not a type (A) SystemError seems to b raised from typeobject.c (line6155): static int
super_init(PyObject *self, PyObject *args, PyObject *kwds)
{...
if (!PyType_Check(type)) {
PyErr_Format(PyExc_SystemError,
"super(): __class__ is not a type (%s)",
Py_TYPE(type)->tp_name);
return -1;
}
break; |
here's a printout of bytecode from script >>>
>>> s = open("super_closure.py").read()
>>> c = compile(s, "super_closure.py", "exec")
>>> t = py3to2.codetree(c)
>>> print( t )
codetree(
co_argcount = 0,
co_cellvars = (),
co_code =
b'Gd\x00\x00\x84\x00\x00d\x01\x00e\x00\x00\x83\x03\x00Z\x01\x00e\x01\x00\x83\x00\x00j\x02\x00\x83\x00\x00\x01d\x02\x00S',
co_filename = 'super_closure.py',
co_firstlineno = 3,
co_flags = 64,
co_freevars = (),
co_kwonlyargcount =0,
co_lnotab = b'\x13\x06',
co_name = '<module>',
co_names = ('object', 'A', 'foo'),
co_nlocals = 0,
co_stacksize = 4,
co_varnames = (),
depth = 0,
co_consts = (
codetree(
co_argcount = 1,
co_cellvars = ('__class__',),
co_code =
b'|\x00\x00Ee\x00\x00Z\x01\x00\x87\x00\x00f\x01\x00d\x00\x00\x86\x00\x00Z\x02\x00\x87\x00\x00S',
co_filename = 'super_closure.py',
co_firstlineno = 3,
co_flags = 2,
co_freevars = (),
co_kwonlyargcount =0,
co_lnotab = b'\n\x01',
co_name = 'A',
co_names = ('__name__', '__module__', 'foo'),
co_nlocals = 1,
co_stacksize = 2,
co_varnames = ('__locals__',),
depth = 1,
co_consts = (
codetree(
co_argcount = 1,
co_cellvars = ('self',),
co_code =
b't\x00\x00\x83\x00\x00S\x87\x00\x00f\x01\x00d\x01\x00\x86\x00\x00\x01',
co_filename = 'super_closure.py',
co_firstlineno = 4,
co_flags = 3,
co_freevars = ('__class__',),
co_kwonlyargcount =0,
co_lnotab = b'\x00\x01\x07\x03',
co_name = 'foo',
co_names = ('super',),
co_nlocals = 1,
co_stacksize = 2,
co_varnames = ('self',),
depth = 2,
co_consts = (
None,
codetree(
co_argcount = 0,
co_cellvars = (),
co_code = b'\x88\x00\x00S',
co_filename = 'super_closure.py',
co_firstlineno = 8,
co_flags = 19,
co_freevars = ('self',),
co_kwonlyargcount =0,
co_lnotab = b'',
co_name = '<lambda>',
co_names = (),
co_nlocals = 0,
co_stacksize = 1,
co_varnames = (),
depth = 3,
co_consts = (
)),
)),
)),
A,
None,
))
>>> and disassembly: >>>
>>> print( t.dis() )
3 0 LOAD_BUILD_CLASS
1 LOAD_CONST 0 (<code object A at
0x2a987af9b0, file "super_closure.py", line 3>)
4 MAKE_FUNCTION 0
7 LOAD_CONST 1 ('A')
10 LOAD_NAME 0 (object)
13 CALL_FUNCTION 3
16 STORE_NAME 1 (A) 9 19 LOAD_NAME 1 (A)
0x2a987afd30, file "super_closure.py", line 4>)
<lambda> at 0x2a984c0530, file "super_closure.py", line 8>)
|
same thing, except w/ closure commented out (& everything is happy) ################################
# super_ok.py
class A(object):
def foo(self):
return super()
# comment the closure below
# & SystemError goes away
# lambda: self
A().foo()
################################ >>>
>>> s = open("super_ok.py").read()
>>> c = compile(s, "super_ok.py", "exec")
>>> t = py3to2.codetree(t)
>>> print( t )
codetree(
co_argcount = 0,
co_cellvars = (),
co_code =
b'Gd\x00\x00\x84\x00\x00d\x01\x00e\x00\x00\x83\x03\x00Z\x01\x00e\x01\x00\x83\x00\x00j\x02\x00\x83\x00\x00\x01d\x02\x00S',
co_filename = 'super_closure.py',
co_firstlineno = 3,
co_flags = 64,
co_freevars = (),
co_kwonlyargcount =0,
co_lnotab = b'\x13\x06',
co_name = '<module>',
co_names = ('object', 'A', 'foo'),
co_nlocals = 0,
co_stacksize = 4,
co_varnames = (),
depth = 0,
co_consts = (
codetree(
co_argcount = 1,
co_cellvars = ('__class__',),
co_code =
b'|\x00\x00Ee\x00\x00Z\x01\x00\x87\x00\x00f\x01\x00d\x00\x00\x86\x00\x00Z\x02\x00\x87\x00\x00S',
co_filename = 'super_closure.py',
co_firstlineno = 3,
co_flags = 2,
co_freevars = (),
co_kwonlyargcount =0,
co_lnotab = b'\n\x01',
co_name = 'A',
co_names = ('__name__', '__module__', 'foo'),
co_nlocals = 1,
co_stacksize = 2,
co_varnames = ('__locals__',),
depth = 1,
co_consts = (
codetree(
co_argcount = 1,
co_cellvars = ('self',),
co_code =
b't\x00\x00\x83\x00\x00S\x87\x00\x00f\x01\x00d\x01\x00\x86\x00\x00\x01',
co_filename = 'super_closure.py',
co_firstlineno = 4,
co_flags = 3,
co_freevars = ('__class__',),
co_kwonlyargcount =0,
co_lnotab = b'\x00\x01\x07\x03',
co_name = 'foo',
co_names = ('super',),
co_nlocals = 1,
co_stacksize = 2,
co_varnames = ('self',),
depth = 2,
co_consts = (
None,
codetree(
co_argcount = 0,
co_cellvars = (),
co_code = b'\x88\x00\x00S',
co_filename = 'super_closure.py',
co_firstlineno = 8,
co_flags = 19,
co_freevars = ('self',),
co_kwonlyargcount =0,
co_lnotab = b'',
co_name = '<lambda>',
co_names = (),
co_nlocals = 0,
co_stacksize = 1,
co_varnames = (),
depth = 3,
co_consts = (
)),
)),
)),
A,
None,
))
>>>
>>> print( t.dis() )
3 0 LOAD_BUILD_CLASS
1 LOAD_CONST 0 (<code object A at
0x2a987af2b0, file "super_closure.py", line 3>)
4 MAKE_FUNCTION 0
7 LOAD_CONST 1 ('A')
10 LOAD_NAME 0 (object)
13 CALL_FUNCTION 3
16 STORE_NAME 1 (A) 9 19 LOAD_NAME 1 (A)
0x2a987af4b0, file "super_closure.py", line 4>)
<lambda> at 0x2a987af5b0, file "super_closure.py", line 8>)
|
oops, sorry reprinted the same code ^^;;; ignore previous post, & use ################################
# super_ok.py
class A(object):
def foo(self):
return super()
# comment the closure below
# & SystemError goes away
# lambda: self
A().foo()
################################ >>> s = open("super_ok.py").read(); c = compile(s, "super_ok.py",
"exec"); t = py3to2.codetree(c)
>>> print( t )
codetree(
co_argcount = 0,
co_cellvars = (),
co_code =
b'Gd\x00\x00\x84\x00\x00d\x01\x00e\x00\x00\x83\x03\x00Z\x01\x00e\x01\x00\x83\x00\x00j\x02\x00\x83\x00\x00\x01d\x02\x00S',
co_filename = 'super_ok.py',
co_firstlineno = 3,
co_flags = 64,
co_freevars = (),
co_kwonlyargcount =0,
co_lnotab = b'\x13\x06',
co_name = '<module>',
co_names = ('object', 'A', 'foo'),
co_nlocals = 0,
co_stacksize = 4,
co_varnames = (),
depth = 0,
co_consts = (
codetree(
co_argcount = 1,
co_cellvars = ('__class__',),
co_code =
b'|\x00\x00Ee\x00\x00Z\x01\x00\x87\x00\x00f\x01\x00d\x00\x00\x86\x00\x00Z\x02\x00\x87\x00\x00S',
co_filename = 'super_ok.py',
co_firstlineno = 3,
co_flags = 2,
co_freevars = (),
co_kwonlyargcount =0,
co_lnotab = b'\n\x01',
co_name = 'A',
co_names = ('__name__', '__module__', 'foo'),
co_nlocals = 1,
co_stacksize = 2,
co_varnames = ('__locals__',),
depth = 1,
co_consts = (
codetree(
co_argcount = 1,
co_cellvars = (),
co_code = b't\x00\x00\x83\x00\x00S',
co_filename = 'super_ok.py',
co_firstlineno = 4,
co_flags = 3,
co_freevars = ('__class__',),
co_kwonlyargcount =0,
co_lnotab = b'\x00\x01',
co_name = 'foo',
co_names = ('super',),
co_nlocals = 1,
co_stacksize = 1,
co_varnames = ('self',),
depth = 2,
co_consts = (
None,
)),
)),
A,
None,
))
>>> print( t.dis() )
3 0 LOAD_BUILD_CLASS
1 LOAD_CONST 0 (<code object A at
0x2a987afd30, file "super_ok.py", line 3>)
4 MAKE_FUNCTION 0
7 LOAD_CONST 1 ('A')
10 LOAD_NAME 0 (object)
13 CALL_FUNCTION 3
16 STORE_NAME 1 (A) 9 19 LOAD_NAME 1 (A)
0x2a984c0530, file "super_ok.py", line 4>)
|
In a running frame, f->f_localplus is a vector composed of:
super() needs to access the free var containing the enclosing class The attached patch corrects the problem. |
Yet another release blocker for Barry. Good work, Amaury. |
The patch looks good to me. |
patch applied; r67299 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: