Skip to content

Commit 92c943b

Browse files
committed
fix bad first arg
1 parent 9384106 commit 92c943b

File tree

3 files changed

+233
-227
lines changed

3 files changed

+233
-227
lines changed

Lib/test/test_super.py

+8
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,14 @@ def method(self):
385385
with self.assertRaisesRegex(AttributeError, "'super' object has no attribute 'msg'"):
386386
C().method()
387387

388+
def test_bad_first_arg(self):
389+
class C:
390+
def method(self):
391+
return super(1, self).method()
392+
393+
with self.assertRaisesRegex(TypeError, "argument 1 must be a type"):
394+
C().method()
395+
388396

389397
if __name__ == "__main__":
390398
unittest.main()

Python/bytecodes.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1556,10 +1556,9 @@ dummy_func(
15561556

15571557
inst(LOAD_SUPER_ATTR, (global_super, class, self -- res2 if (oparg & 1), res)) {
15581558
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
1559-
if (global_super == (PyObject *)&PySuper_Type) {
1559+
if (global_super == (PyObject *)&PySuper_Type && PyType_Check(class)) {
15601560
int meth_found = 0;
15611561
Py_DECREF(global_super);
1562-
assert(PyType_Check(class));
15631562
res = _PySuper_Lookup((PyTypeObject *)class, self, name, oparg & 1 ? &meth_found : NULL);
15641563
Py_DECREF(class);
15651564
if (res == NULL) {

0 commit comments

Comments
 (0)