Skip to content

Commit 3d19fc9

Browse files
[mypyc] Fix __call__ subclasses (#13152)
Fixes #12605 Fixes mypyc/mypyc#925
1 parent baf4af4 commit 3d19fc9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

mypyc/codegen/emitclass.py

+4
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ def emit_line() -> None:
322322
fields['tp_vectorcall_offset'] = 'offsetof({}, vectorcall)'.format(
323323
cl.struct_name(emitter.names))
324324
flags.append('_Py_TPFLAGS_HAVE_VECTORCALL')
325+
if not fields.get('tp_vectorcall'):
326+
# This is just a placeholder to please CPython. It will be
327+
# overriden during setup.
328+
fields['tp_call'] = 'PyVectorcall_Call'
325329
fields['tp_flags'] = ' | '.join(flags)
326330

327331
emitter.emit_line(f"static PyTypeObject {emitter.type_struct_name(cl)}_template_ = {{")

mypyc/test-data/run-classes.test

+10
Original file line numberDiff line numberDiff line change
@@ -2206,3 +2206,13 @@ def test_serializable_sub_class_call_new() -> None:
22062206
base: NonSerializable = sub
22072207
with assertRaises(AttributeError):
22082208
base.s
2209+
2210+
[case testClassWithInherited__call__]
2211+
class Base:
2212+
def __call__(self) -> int:
2213+
return 1
2214+
2215+
class Derived(Base):
2216+
pass
2217+
2218+
assert Derived()() == 1

0 commit comments

Comments
 (0)