(
fn: FuncIR, emitter: Emitter, gen: WrapperGenerator
)
| 360 | |
| 361 | |
| 362 | def generate_bin_op_forward_only_wrapper( |
| 363 | fn: FuncIR, emitter: Emitter, gen: WrapperGenerator |
| 364 | ) -> None: |
| 365 | gen.emit_arg_processing(error=GotoHandler("typefail"), raise_exception=False) |
| 366 | handle_third_pow_argument(fn, emitter, gen, if_unsupported=["goto typefail;"]) |
| 367 | gen.emit_call(not_implemented_handler="goto typefail;") |
| 368 | gen.emit_error_handling() |
| 369 | emitter.emit_label("typefail") |
| 370 | # If some argument has an incompatible type, treat this the same as |
| 371 | # returning NotImplemented, and try to call the reverse operator method. |
| 372 | # |
| 373 | # Note that in normal Python you'd instead of an explicit |
| 374 | # return of NotImplemented, but it doesn't generally work here |
| 375 | # the body won't be executed at all if there is an argument |
| 376 | # type check failure. |
| 377 | # |
| 378 | # The recommended way is to still use a type check in the |
| 379 | # body. This will only be used in interpreted mode: |
| 380 | # |
| 381 | # def __add__(self, other: int) -> Foo: |
| 382 | # if not isinstance(other, int): |
| 383 | # return NotImplemented |
| 384 | # ... |
| 385 | generate_bin_op_reverse_dunder_call(fn, emitter, reverse_op_methods[fn.name]) |
| 386 | gen.finish() |
| 387 | |
| 388 | |
| 389 | def generate_bin_op_reverse_only_wrapper( |
no test coverage detected
searching dependent graphs…