Skip to content

Commit

Permalink
pythongh-105035: fix super() calls on unusual types (e.g. meta-types)
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed May 30, 2023
1 parent b7aadb4 commit 4ef2316
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 219 deletions.
12 changes: 12 additions & 0 deletions Lib/test/test_super.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,18 @@ def method(self):

self.assertEqual(C().method(), mysuper)

def test_unusual_getattro(self):
class MyType(type):
pass

def test(name):
mytype = MyType(name, (MyType,), {})
super(MyType, type(mytype)).__setattr__(mytype, "bar", 1)
self.assertEqual(mytype.bar, 1)

test("foo1")
test("foo2")


if __name__ == "__main__":
unittest.main()
1 change: 1 addition & 0 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,7 @@ dummy_func(
assert(oparg & 1);
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
DEOPT_IF(((PyTypeObject *)class)->tp_getattro != PyObject_GenericGetAttr, LOAD_SUPER_ATTR);
STAT_INC(LOAD_SUPER_ATTR, hit);
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
int method_found = 0;
Expand Down
Loading

0 comments on commit 4ef2316

Please sign in to comment.