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

Function generate_contains_wrapper

mypyc/codegen/emitwrapper.py:719–738  ·  view source on GitHub ↗

Generates a wrapper for a native __contains__ method.

(cl: ClassIR, fn: FuncIR, emitter: Emitter)

Source from the content-addressed store, hash-verified

717
718
719def generate_contains_wrapper(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str:
720 """Generates a wrapper for a native __contains__ method."""
721 name = f"{DUNDER_PREFIX}{fn.name}{cl.name_prefix(emitter.names)}"
722 emitter.emit_line(f"static int {name}(PyObject *self, PyObject *obj_item) {{")
723 generate_arg_check("item", fn.args[1].type, emitter, ReturnHandler("-1"))
724 emitter.emit_line(
725 "{}val = {}(self, arg_item);".format(
726 emitter.ctype_spaced(fn.ret_type), emitter.native_function_call(fn.decl)
727 )
728 )
729 emitter.emit_error_check("val", fn.ret_type, "return -1;")
730 if is_bool_rprimitive(fn.ret_type):
731 emitter.emit_line("return val;")
732 else:
733 emitter.emit_line("int boolval = PyObject_IsTrue(val);")
734 emitter.emit_dec_ref("val", fn.ret_type)
735 emitter.emit_line("return boolval;")
736 emitter.emit_line("}")
737
738 return name
739
740
741# Helpers

Callers

nothing calls this directly

Calls 10

ReturnHandlerClass · 0.90
is_bool_rprimitiveFunction · 0.90
generate_arg_checkFunction · 0.85
name_prefixMethod · 0.80
ctype_spacedMethod · 0.80
native_function_callMethod · 0.80
emit_error_checkMethod · 0.80
emit_lineMethod · 0.45
formatMethod · 0.45
emit_dec_refMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…