MCPcopy Index your code
hub / github.com/python/mypy / handle_non_ext_method

Function handle_non_ext_method

mypyc/irbuild/function.py:562–599  ·  view source on GitHub ↗
(
    builder: IRBuilder, non_ext: NonExtClassInfo, cdef: ClassDef, fdef: FuncDef
)

Source from the content-addressed store, hash-verified

560
561
562def handle_non_ext_method(
563 builder: IRBuilder, non_ext: NonExtClassInfo, cdef: ClassDef, fdef: FuncDef
564) -> None:
565 # Perform the function of visit_method for methods inside non-extension classes.
566 name = fdef.name
567 sig = builder.mapper.fdef_to_sig(fdef, builder.options.strict_dunders_typing)
568 func_ir, func_reg = gen_func_item(builder, fdef, name, sig, cdef)
569 assert func_reg is not None
570 builder.functions.append(func_ir)
571
572 if is_decorated(builder, fdef):
573 # The undecorated method is a generated callable class
574 orig_func = func_reg
575 func_reg = load_decorated_func(builder, fdef, orig_func)
576
577 # TODO: Support property setters in non-extension classes
578 if fdef.is_property:
579 prop = builder.load_module_attr_by_fullname("builtins.property", fdef.line)
580 func_reg = builder.py_call(prop, [func_reg], fdef.line)
581
582 elif builder.mapper.func_to_decl[fdef].kind == FUNC_CLASSMETHOD:
583 cls_meth = builder.load_module_attr_by_fullname("builtins.classmethod", fdef.line)
584 func_reg = builder.py_call(cls_meth, [func_reg], fdef.line)
585
586 elif builder.mapper.func_to_decl[fdef].kind == FUNC_STATICMETHOD:
587 stat_meth = builder.load_module_attr_by_fullname("builtins.staticmethod", fdef.line)
588 func_reg = builder.py_call(stat_meth, [func_reg], fdef.line)
589
590 builder.add_to_non_ext_dict(non_ext, name, func_reg, fdef.line)
591
592 # If we identified that this non-extension class method can be special-cased for
593 # direct access during prepare phase, generate a "static" version of it.
594 class_ir = builder.mapper.type_to_ir[cdef.info]
595 name = FAST_PREFIX + fdef.name
596 if name in class_ir.method_decls:
597 func_ir, func_reg = gen_func_item(builder, fdef, name, sig, cdef, make_ext_method=True)
598 class_ir.methods[name] = func_ir
599 builder.functions.append(func_ir)
600
601
602def gen_func_ns(builder: IRBuilder) -> str:

Callers 1

add_methodMethod · 0.90

Calls 8

gen_func_itemFunction · 0.85
is_decoratedFunction · 0.85
load_decorated_funcFunction · 0.85
fdef_to_sigMethod · 0.80
appendMethod · 0.80
add_to_non_ext_dictMethod · 0.80
py_callMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…