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

Function generate_ipow_wrapper

mypyc/codegen/emitwrapper.py:304–327  ·  view source on GitHub ↗

Generate a wrapper for native __ipow__. Since __ipow__ fills a ternary slot, but almost no one defines __ipow__ to take three arguments, the wrapper needs to tweaked to force it to accept three arguments.

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

Source from the content-addressed store, hash-verified

302
303
304def generate_ipow_wrapper(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str:
305 """Generate a wrapper for native __ipow__.
306
307 Since __ipow__ fills a ternary slot, but almost no one defines __ipow__ to take three
308 arguments, the wrapper needs to tweaked to force it to accept three arguments.
309 """
310 gen = WrapperGenerator(cl, emitter)
311 gen.set_target(fn)
312 assert len(fn.args) in (2, 3), "__ipow__ should only take 2 or 3 arguments"
313 gen.arg_names = ["self", "exp", "mod"]
314 gen.emit_header()
315 gen.emit_arg_processing()
316 handle_third_pow_argument(
317 fn,
318 emitter,
319 gen,
320 if_unsupported=[
321 'PyErr_SetString(PyExc_TypeError, "__ipow__ takes 2 positional arguments but 3 were given");',
322 "return NULL;",
323 ],
324 )
325 gen.emit_call()
326 gen.finish()
327 return gen.wrapper_name()
328
329
330def generate_bin_op_wrapper(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str:

Callers

nothing calls this directly

Calls 9

set_targetMethod · 0.95
emit_headerMethod · 0.95
emit_arg_processingMethod · 0.95
emit_callMethod · 0.95
finishMethod · 0.95
wrapper_nameMethod · 0.95
WrapperGeneratorClass · 0.85
lenFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…