From 786cfa0d0d914c1438aa176b3d990d6cf75ea837 Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Fri, 26 Oct 2018 08:20:26 -0700 Subject: MAINT: set __module__ for more array_function_dispatch uses I noticed a few more functions using ``array_function_dispatch`` where I had not set the module, using this script:: import types def check_module(module): for name in dir(module): item = getattr(module, name) if isinstance(item, types.FunctionType): print(f'{item.__module__}.{item.__name__}') >>> import numpy >>> check_module(numpy) ... Note that functions without overrides like ``numpy.ones`` still display the module in which they are defined, e.g., ``numpy.core.numeric.ones``. We should probably fix that, too, probably most cleanly adding a decorator that sets ``__module__``, e.g., def set_module(module): def decorator(func): func.__module__ = module return func return decorator ... @set_module('numpy') def ones(shape, dtype=None, order='C'): ... --- numpy/core/shape_base.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'numpy/core/shape_base.py') diff --git a/numpy/core/shape_base.py b/numpy/core/shape_base.py index c9f8ebccb..71a23f438 100644 --- a/numpy/core/shape_base.py +++ b/numpy/core/shape_base.py @@ -7,9 +7,13 @@ import functools import operator from . import numeric as _nx +from . import overrides from .numeric import array, asanyarray, newaxis from .multiarray import normalize_axis_index -from .overrides import array_function_dispatch + + +array_function_dispatch = functools.partial( + overrides.array_function_dispatch, module='numpy') def _atleast_1d_dispatcher(*arys): -- cgit v1.2.1