Skip to content

Commit 710bcf7

Browse files
committed
Add comment for __new__ method lookup
1 parent cab2f70 commit 710bcf7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

mypyc/irbuild/prepare.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,13 @@ def prepare_init_method(cdef: ClassDef, ir: ClassIR, module_name: str, mapper: M
578578
init_node = cdef.info["__init__"].node
579579

580580
new_node: SymbolNode | None = None
581-
new_typeinfo = cdef.info.get("__new__")
582-
if new_typeinfo and new_typeinfo.fullname and not new_typeinfo.fullname.startswith("builtins"):
583-
new_node = new_typeinfo.node
581+
new_symbol = cdef.info.get("__new__")
582+
# We are only interested in __new__ method defined in a user-defined class,
583+
# so we ignore it if it comes from a builtin type. It's usually builtins.object
584+
# but could also be builtins.type for metaclasses so we detect the prefix which
585+
# matches both.
586+
if new_symbol and new_symbol.fullname and not new_symbol.fullname.startswith("builtins."):
587+
new_node = new_symbol.node
584588
if isinstance(new_node, (Decorator, OverloadedFuncDef)):
585589
new_node = get_func_def(new_node)
586590
if not ir.is_trait and not ir.builtin_base and isinstance(init_node, FuncDef):

0 commit comments

Comments
 (0)