From a5c4b7ac576ef803566e5db1edf6e715c76b4a1d Mon Sep 17 00:00:00 2001 From: Sebastian Larsson Date: Thu, 6 Nov 2025 16:29:23 +0100 Subject: [PATCH] Arm backend: Add docstrings for tosa/dialect/lib.py Change-Id: Ideabb08fdeb6e9688d7da8a7f9be1b9ee3c8d484 Signed-off-by: Sebastian Larsson --- backends/arm/tosa/dialect/lib.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/backends/arm/tosa/dialect/lib.py b/backends/arm/tosa/dialect/lib.py index 4a807d682dc..ed26a21a297 100644 --- a/backends/arm/tosa/dialect/lib.py +++ b/backends/arm/tosa/dialect/lib.py @@ -15,6 +15,17 @@ def register_tosa_dialect_op(op_schema, func) -> Callable: + """Register a TOSA dialect operator with the backend op library. + + Args: + op_schema (str): Operator schema without namespace or overload name. + func (Callable): Fake implementation used for registration. + + Returns: + Callable: Backend dialect operator handle exposed via ``exir_ops`` and + marked ``not_callable`` for runtime use. + + """ if tosa_lib.ns not in _BACKEND_OP_LIB: _BACKEND_OP_LIB.append(tosa_lib.ns) @@ -43,6 +54,7 @@ def register_tosa_dialect_op(op_schema, func) -> Callable: # the op doesn't need to be callable. This can be changed in the future if needed to support # execution of TOSA ops directly. def not_callable(): + """Raise when the dialect op handle is invoked at runtime.""" raise RuntimeError("TOSA dialect op is not callable") op.__equvalent_callable__ = not_callable @@ -51,11 +63,22 @@ def not_callable(): class TosaValueError(ValueError): + """Error type that annotates failures with the originating TOSA op.""" + def __init__(self, message="A TOSA value error occurred", *args, op=None): + """Initialise the error with optional operator metadata. + + Args: + message (str): Human-readable error message. + *args: Additional arguments forwarded to ``ValueError``. + op: Optional operator identifier included in the string output. + + """ super().__init__(message, *args) self.op = op def __str__(self): + """Return the base message, appending the operator when provided.""" base_message = super().__str__() if self.op is not None: return f"{base_message} (TOSA op: {self.op})"