Skip to content

Commit

Permalink
fix bad first arg
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Apr 13, 2023
1 parent 9384106 commit 92c943b
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 227 deletions.
8 changes: 8 additions & 0 deletions Lib/test/test_super.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ def method(self):
with self.assertRaisesRegex(AttributeError, "'super' object has no attribute 'msg'"):
C().method()

def test_bad_first_arg(self):
class C:
def method(self):
return super(1, self).method()

with self.assertRaisesRegex(TypeError, "argument 1 must be a type"):
C().method()


if __name__ == "__main__":
unittest.main()
3 changes: 1 addition & 2 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1556,10 +1556,9 @@ dummy_func(

inst(LOAD_SUPER_ATTR, (global_super, class, self -- res2 if (oparg & 1), res)) {
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
if (global_super == (PyObject *)&PySuper_Type) {
if (global_super == (PyObject *)&PySuper_Type && PyType_Check(class)) {
int meth_found = 0;
Py_DECREF(global_super);
assert(PyType_Check(class));
res = _PySuper_Lookup((PyTypeObject *)class, self, name, oparg & 1 ? &meth_found : NULL);
Py_DECREF(class);
if (res == NULL) {
Expand Down

0 comments on commit 92c943b

Please sign in to comment.