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

Method emit_cpyfunction_instance

mypyc/codegen/emit.py:1425–1442  ·  view source on GitHub ↗
(
        self, fn: FuncIR, name: str, filepath: str, error_stmt: str
    )

Source from the content-addressed store, hash-verified

1423 self.emit_line("}")
1424
1425 def emit_cpyfunction_instance(
1426 self, fn: FuncIR, name: str, filepath: str, error_stmt: str
1427 ) -> str:
1428 module = self.static_name(fn.decl.module_name, None, prefix=MODULE_PREFIX)
1429 cname = f"{PREFIX}{fn.cname(self.names)}"
1430 wrapper_name = f"{cname}_wrapper"
1431 cfunc = f"(PyCFunction){cname}"
1432 func_flags = "METH_FASTCALL | METH_KEYWORDS"
1433 doc = f"PyDoc_STR({native_function_doc_initializer(fn)})"
1434 has_self_arg = "true" if fn.class_name and fn.decl.kind != FUNC_STATICMETHOD else "false"
1435
1436 code_flags = "CO_COROUTINE"
1437 self.emit_line(
1438 f'PyObject* {wrapper_name} = CPyFunction_New({module}, "{filepath}", "{name}", {cfunc}, {func_flags}, {doc}, {fn.line}, {code_flags}, {has_self_arg});'
1439 )
1440 self.emit_line(f"if (unlikely(!{wrapper_name}))")
1441 self.emit_line(error_stmt)
1442 return wrapper_name
1443
1444 def emit_base_tp_function_call(
1445 self, derived_cl: ClassIR, tp_func: str, args: str, *, prefix: str = ""

Callers 2

emit_instanceFunction · 0.80

Calls 4

static_nameMethod · 0.95
emit_lineMethod · 0.95
cnameMethod · 0.45

Tested by

no test coverage detected