set_value_magic_handler¶

onnx_ir.set_value_magic_handler(handler)¶

Set the magic handler for Value arithmetic methods.

Framework authors can implement custom context managers that set the magic handler to enable arithmetic operations on Values.

Example:

class MyOpHandler:
    def Add(self, lhs, rhs):
        # Implement addition logic here
        pass
    ...

@contextlib.contextmanager
def graph_context(graph):
    old_handler = onnx_ir.set_value_magic_handler(MyOpHandler(graph))
    try:
        yield
    finally:
        onnx_ir.set_value_magic_handler(old_handler)
Parameters:

handler (_OpHandlerProtocol | None) – The magic handler to set.

Returns:

The previous magic handler.

Return type:

_OpHandlerProtocol | None