From 9ddb0da647ba02fac46785a385ffaa0819118cad Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Thu, 15 Oct 2026 11:19:13 +0100 Subject: [PATCH] [mypyc] Fix compile error in tp_setattro wrapper slot Fix conflict between #22161 and #22145. --- mypyc/codegen/emitclass.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mypyc/codegen/emitclass.py b/mypyc/codegen/emitclass.py index 830d6148e582..2b619f58636b 100644 --- a/mypyc/codegen/emitclass.py +++ b/mypyc/codegen/emitclass.py @@ -63,6 +63,11 @@ def native_slot(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str: return f"{NATIVE_PREFIX}{fn.cname(emitter.names)}" +def wrapper_slot(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str: + """Use a generated wrapper function directly as a slot, without boxing its result.""" + return f"{NATIVE_PREFIX}{fn.cname(emitter.names)}" + + def dunder_attr_slot(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str: wrapper_fn = cl.get_method(fn.name + "__wrapper") assert wrapper_fn @@ -88,7 +93,7 @@ def dunder_attr_slot(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str: "__getattr__": ("tp_getattro", dunder_attr_slot), # The wrapper is also generated for a class that defines only __delattr__, so fill # the slot based on the wrapper instead of __setattr__. - "__setattr____wrapper": ("tp_setattro", native_slot), + "__setattr____wrapper": ("tp_setattro", wrapper_slot), } AS_MAPPING_SLOT_DEFS: SlotTable = {