Skip to content

Commit a545d27

Browse files
committed
fix: set Py_TPFLAGS_MANAGED_WEAKREF flag on python>=3.12
1 parent e17d8c8 commit a545d27

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mypyc/codegen/emitclass.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ def emit_line() -> None:
323323
"};",
324324
)
325325
if emitter.capi_version < (3, 12):
326+
# versions >= 3.12 do not define tp_weaklistoffset, but set Py_TPFLAGS_MANAGED_WEAKREF flag instead
326327
fields["tp_weaklistoffset"] = base_size
327328
else:
328329
fields["tp_basicsize"] = base_size
@@ -384,6 +385,9 @@ def emit_line() -> None:
384385
fields["tp_call"] = "PyVectorcall_Call"
385386
if has_managed_dict(cl, emitter):
386387
flags.append("Py_TPFLAGS_MANAGED_DICT")
388+
if cl.supports_weakref and emitter.capi_version >= (3, 12):
389+
flags.append("Py_TPFLAGS_MANAGED_WEAKREF")
390+
387391
fields["tp_flags"] = " | ".join(flags)
388392

389393
fields["tp_doc"] = native_class_doc_initializer(cl)

0 commit comments

Comments
 (0)