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

Function generate_bool_wrapper

mypyc/codegen/emitwrapper.py:598–615  ·  view source on GitHub ↗

Generates a wrapper for native __bool__ methods.

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

Source from the content-addressed store, hash-verified

596
597
598def generate_bool_wrapper(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str:
599 """Generates a wrapper for native __bool__ methods."""
600 name = f"{DUNDER_PREFIX}{fn.name}{cl.name_prefix(emitter.names)}"
601 emitter.emit_line(f"static int {name}(PyObject *self) {{")
602 emitter.emit_line(
603 "{}val = {}(self);".format(
604 emitter.ctype_spaced(fn.ret_type), emitter.native_function_call(fn.decl)
605 )
606 )
607 emitter.emit_error_check("val", fn.ret_type, "return -1;")
608 # This wouldn't be that hard to fix but it seems unimportant and
609 # getting error handling and unboxing right would be fiddly. (And
610 # way easier to do in IR!)
611 assert is_bool_rprimitive(fn.ret_type), "Only bool return supported for __bool__"
612 emitter.emit_line("return val;")
613 emitter.emit_line("}")
614
615 return name
616
617
618def generate_del_item_wrapper(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str:

Callers

nothing calls this directly

Calls 7

is_bool_rprimitiveFunction · 0.90
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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…