UniCoreFW

bind_all()

Bind specified methods of obj to obj itself.

Implementation

Args: obj: The object to bind methods to *method_names: Names of methods to bind Returns: None

Example

class A: def add(self, x, y): return x + y bind_all(A(), 'add') a = A() a.add(1, 2)

Expected output: 3

Source Code

def bind_all(obj: Any, *method_names: str) -> None: for method_name in method_names: if hasattr(obj, method_name): bound_method = getattr(obj, method_name).__get__(obj) setattr(obj, method_name, bound_method)