Improved handling for __array_fuction__ submodules
@@ -1242,14 +1242,18 @@ cdef class ndarray:
return NotImplemented
def __array_function__(self, func, types, args, kwargs):
- module_list = '.'.join(func.__module__.split('.')[1:])
- cupy_module = eval('cupy.' + module_list if module_list else 'cupy')
- if not hasattr(cupy_module, func.__name__):
+ import cupy as module
+ for submodule in func.__module__.split('.')[1:]:
+ try:
+ module = getattr(module, submodule)
+ except AttributeError:
+ return NotImplemented
+ if not hasattr(module, func.__name__):
return NotImplemented
for t in types:
if t not in _HANDLED_TYPES:
return NotImplemented
- return getattr(cupy_module, func.__name__)(*args, **kwargs)
+ return getattr(module, func.__name__)(*args, **kwargs)
# Conversion:
