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

Function handle_third_pow_argument

mypyc/codegen/emitwrapper.py:467–488  ·  view source on GitHub ↗
(
    fn: FuncIR, emitter: Emitter, gen: WrapperGenerator, *, if_unsupported: list[str]
)

Source from the content-addressed store, hash-verified

465
466
467def handle_third_pow_argument(
468 fn: FuncIR, emitter: Emitter, gen: WrapperGenerator, *, if_unsupported: list[str]
469) -> None:
470 if fn.name not in ("__pow__", "__rpow__", "__ipow__"):
471 return
472
473 if (fn.name in ("__pow__", "__ipow__") and len(fn.args) == 2) or fn.name == "__rpow__":
474 # If the power dunder only supports two arguments and the third
475 # argument (AKA mod) is set to a non-default value, simply bail.
476 #
477 # Importantly, this prevents any ternary __rpow__ calls from
478 # happening (as per the language specification).
479 emitter.emit_line("if (obj_mod != Py_None) {")
480 for line in if_unsupported:
481 emitter.emit_line(line)
482 emitter.emit_line("}")
483 # The slot wrapper will receive three arguments, but the call only
484 # supports two so make sure that the third argument isn't passed
485 # along. This is needed as two-argument __(i)pow__ is allowed and
486 # rather common.
487 if len(gen.arg_names) == 3:
488 gen.arg_names.pop()
489
490
491RICHCOMPARE_OPS = {

Calls 3

lenFunction · 0.85
emit_lineMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…