From 95848bc06ca25dfeaccece1b2568f364eb5ee93c Mon Sep 17 00:00:00 2001 From: Yusha Arif Date: Sat, 17 Aug 2024 08:31:51 +0000 Subject: [PATCH] fix decorator_utils: improved the implementation of handle_methods decorator to handle cases where the 1st argument is an iterable --- ivy/utils/decorator_utils.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ivy/utils/decorator_utils.py b/ivy/utils/decorator_utils.py index 2e754ea63271..095ae3252a36 100644 --- a/ivy/utils/decorator_utils.py +++ b/ivy/utils/decorator_utils.py @@ -159,13 +159,20 @@ def extract_function_name(s): @functools.wraps(fn) def wrapper(*args, **kwargs): - if ivy.is_array(args[0]): + array_like = args[0] + if isinstance(array_like, (list, tuple)): + array_like = array_like[0] + + if ivy.is_array(array_like): return fn(*args, **kwargs) else: pattern = r"_bknd_|_bknd|_frnt_|_frnt" fn_name = extract_function_name(re.sub(pattern, "", fn.__name__)) - new_fn = getattr(args[0], fn_name) - return new_fn(*args[1:], **kwargs) + try: + new_fn = getattr(array_like, fn_name) + return new_fn(*args[1:], **kwargs) + except AttributeError: + return fn(*args, **kwargs) return wrapper