(
fn: FuncIR, emitter: Emitter, gen: WrapperGenerator, *, if_unsupported: list[str]
)
| 465 | |
| 466 | |
| 467 | def 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 | |
| 491 | RICHCOMPARE_OPS = { |
no test coverage detected
searching dependent graphs…