Skip to content

[mypyc] Fix __call__ subclasses #13152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mypyc/codegen/emitclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_ = {{")
Expand Down
10 changes: 10 additions & 0 deletions mypyc/test-data/run-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -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