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

Function generate_wrapper_core

mypyc/codegen/emitwrapper.py:744–769  ·  view source on GitHub ↗

Generates the core part of a wrapper function for a native function. This expects each argument as a PyObject * named obj_{arg} as a precondition. It converts the PyObject *s to the necessary types, checking and unboxing if necessary, makes the call, then boxes the result if necessary a

(
    fn: FuncIR,
    emitter: Emitter,
    optional_args: list[RuntimeArg] | None = None,
    arg_names: list[str] | None = None,
    cleanups: list[str] | None = None,
    traceback_code: str | None = None,
)

Source from the content-addressed store, hash-verified

742
743
744def generate_wrapper_core(
745 fn: FuncIR,
746 emitter: Emitter,
747 optional_args: list[RuntimeArg] | None = None,
748 arg_names: list[str] | None = None,
749 cleanups: list[str] | None = None,
750 traceback_code: str | None = None,
751) -> None:
752 """Generates the core part of a wrapper function for a native function.
753
754 This expects each argument as a PyObject * named obj_{arg} as a precondition.
755 It converts the PyObject *s to the necessary types, checking and unboxing if necessary,
756 makes the call, then boxes the result if necessary and returns it.
757 """
758 gen = WrapperGenerator(None, emitter)
759 gen.set_target(fn)
760 if arg_names:
761 gen.arg_names = arg_names
762 gen.cleanups = cleanups or []
763 gen.optional_args = optional_args or []
764 gen.traceback_code = traceback_code or ""
765
766 error = ReturnHandler("NULL") if not gen.use_goto() else GotoHandler("fail")
767 gen.emit_arg_processing(error=error)
768 gen.emit_call()
769 gen.emit_error_handling()
770
771
772def generate_arg_check(

Callers 3

Calls 8

set_targetMethod · 0.95
use_gotoMethod · 0.95
emit_arg_processingMethod · 0.95
emit_callMethod · 0.95
emit_error_handlingMethod · 0.95
ReturnHandlerClass · 0.90
GotoHandlerClass · 0.90
WrapperGeneratorClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…