From c5a915ec3233b7926fe1ad6abd820546eab24b99 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Sat, 16 Jul 2022 16:30:49 +0100 Subject: [PATCH 1/2] Fix __call__ subclasses --- mypyc/codegen/emitclass.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mypyc/codegen/emitclass.py b/mypyc/codegen/emitclass.py index ef36da3c414e..3724cab49f93 100644 --- a/mypyc/codegen/emitclass.py +++ b/mypyc/codegen/emitclass.py @@ -322,6 +322,10 @@ def emit_line() -> None: fields['tp_vectorcall_offset'] = 'offsetof({}, vectorcall)'.format( cl.struct_name(emitter.names)) flags.append('_Py_TPFLAGS_HAVE_VECTORCALL') + if not fields.get('tp_vectorcall'): + # This is just a placeholder to please CPython. It will be + # overriden during setup. + fields['tp_call'] = 'PyVectorcall_Call' fields['tp_flags'] = ' | '.join(flags) emitter.emit_line(f"static PyTypeObject {emitter.type_struct_name(cl)}_template_ = {{") From a32edf0c9ff1e759925966bb99e74c3874546c66 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Sat, 16 Jul 2022 16:38:05 +0100 Subject: [PATCH 2/2] Add test --- mypyc/test-data/run-classes.test | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mypyc/test-data/run-classes.test b/mypyc/test-data/run-classes.test index ac42aa26cf58..ea25e911ac37 100644 --- a/mypyc/test-data/run-classes.test +++ b/mypyc/test-data/run-classes.test @@ -2206,3 +2206,13 @@ def test_serializable_sub_class_call_new() -> None: base: NonSerializable = sub with assertRaises(AttributeError): base.s + +[case testClassWithInherited__call__] +class Base: + def __call__(self) -> int: + return 1 + +class Derived(Base): + pass + +assert Derived()() == 1