summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorSebastian Berg <sebastianb@nvidia.com>2022-11-18 15:11:25 +0100
committerSebastian Berg <sebastianb@nvidia.com>2022-11-24 17:03:42 +0100
commit7c361420b4f81713f593ebbb5c924121c1f2d19d (patch)
tree4fa5c173c3e4df5dfdb9b14b9b0988db0bc69e91 /numpy/core
parent72af24df557802015820714aaa3d105d53216431 (diff)
downloadnumpy-7c361420b4f81713f593ebbb5c924121c1f2d19d.tar.gz
MAINT: Move set_module to numpy.core to use without C import
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/_exceptions.py2
-rw-r--r--numpy/core/_machar.py6
-rw-r--r--numpy/core/_ufunc_config.py2
-rw-r--r--numpy/core/defchararray.py3
-rw-r--r--numpy/core/getlimits.py2
-rw-r--r--numpy/core/memmap.py2
-rw-r--r--numpy/core/numerictypes.py4
-rw-r--r--numpy/core/overrides.py19
-rw-r--r--numpy/core/records.py2
9 files changed, 13 insertions, 29 deletions
diff --git a/numpy/core/_exceptions.py b/numpy/core/_exceptions.py
index be3aa8bee..db5dfea02 100644
--- a/numpy/core/_exceptions.py
+++ b/numpy/core/_exceptions.py
@@ -5,7 +5,7 @@ in python where it's easier.
By putting the formatting in `__str__`, we also avoid paying the cost for
users who silence the exceptions.
"""
-from numpy.core.overrides import set_module
+from .._utils import set_module
def _unpack_tuple(tup):
if len(tup) == 1:
diff --git a/numpy/core/_machar.py b/numpy/core/_machar.py
index 3cc7db278..0a942d98a 100644
--- a/numpy/core/_machar.py
+++ b/numpy/core/_machar.py
@@ -7,9 +7,9 @@ Author: Pearu Peterson, September 2003
"""
__all__ = ['MachAr']
-from numpy.core.fromnumeric import any
-from numpy.core._ufunc_config import errstate
-from numpy.core.overrides import set_module
+from .fromnumeric import any
+from ._ufunc_config import errstate
+from .._utils import set_module
# Need to speed this up...especially for longfloat
diff --git a/numpy/core/_ufunc_config.py b/numpy/core/_ufunc_config.py
index 5aac7ab09..df8213095 100644
--- a/numpy/core/_ufunc_config.py
+++ b/numpy/core/_ufunc_config.py
@@ -7,7 +7,7 @@ import collections.abc
import contextlib
import contextvars
-from .overrides import set_module
+from .._utils import set_module
from .umath import (
UFUNC_BUFSIZE_DEFAULT,
ERR_IGNORE, ERR_WARN, ERR_RAISE, ERR_CALL, ERR_PRINT, ERR_LOG, ERR_DEFAULT,
diff --git a/numpy/core/defchararray.py b/numpy/core/defchararray.py
index 6750e497a..d312506ff 100644
--- a/numpy/core/defchararray.py
+++ b/numpy/core/defchararray.py
@@ -16,12 +16,13 @@ The preferred alias for `defchararray` is `numpy.char`.
"""
import functools
+
+from .._utils import set_module
from .numerictypes import (
string_, unicode_, integer, int_, object_, bool_, character)
from .numeric import ndarray, compare_chararrays
from .numeric import array as narray
from numpy.core.multiarray import _vec_string
-from numpy.core.overrides import set_module
from numpy.core import overrides
from numpy.compat import asbytes
import numpy
diff --git a/numpy/core/getlimits.py b/numpy/core/getlimits.py
index 2c0f462cc..c884e3d70 100644
--- a/numpy/core/getlimits.py
+++ b/numpy/core/getlimits.py
@@ -5,8 +5,8 @@ __all__ = ['finfo', 'iinfo']
import warnings
+from .._utils import set_module
from ._machar import MachAr
-from .overrides import set_module
from . import numeric
from . import numerictypes as ntypes
from .numeric import array, inf, NaN
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py
index b0d9cb3af..5071c909a 100644
--- a/numpy/core/memmap.py
+++ b/numpy/core/memmap.py
@@ -1,9 +1,9 @@
from contextlib import nullcontext
import numpy as np
+from .._utils import set_module
from .numeric import uint8, ndarray, dtype
from numpy.compat import os_fspath, is_pathlib_path
-from numpy.core.overrides import set_module
__all__ = ['memmap']
diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py
index 3d1cb6fd1..37fb8ee62 100644
--- a/numpy/core/numerictypes.py
+++ b/numpy/core/numerictypes.py
@@ -81,11 +81,11 @@ Exported symbols include:
"""
import numbers
-from numpy.core.multiarray import (
+from .multiarray import (
ndarray, array, dtype, datetime_data, datetime_as_string,
busday_offset, busday_count, is_busday, busdaycalendar
)
-from numpy.core.overrides import set_module
+from .._utils import set_module
# we add more at the bottom
__all__ = ['sctypeDict', 'sctypes',
diff --git a/numpy/core/overrides.py b/numpy/core/overrides.py
index 450464f89..6bd72063a 100644
--- a/numpy/core/overrides.py
+++ b/numpy/core/overrides.py
@@ -3,6 +3,7 @@ import collections
import functools
import os
+from .._utils import set_module
from numpy.core._multiarray_umath import (
add_docstring, implement_array_function, _get_implementing_args)
from numpy.compat._inspect import getargspec
@@ -107,24 +108,6 @@ def verify_matching_signatures(implementation, dispatcher):
'default argument values')
-def set_module(module):
- """Decorator for overriding __module__ on a function or class.
-
- Example usage::
-
- @set_module('numpy')
- def example():
- pass
-
- assert example.__module__ == 'numpy'
- """
- def decorator(func):
- if module is not None:
- func.__module__ = module
- return func
- return decorator
-
-
def array_function_dispatch(dispatcher, module=None, verify=True,
docs_from_dispatcher=False):
"""Decorator for adding dispatch with the __array_function__ protocol.
diff --git a/numpy/core/records.py b/numpy/core/records.py
index c014bc97c..0fb49e8f7 100644
--- a/numpy/core/records.py
+++ b/numpy/core/records.py
@@ -37,10 +37,10 @@ import warnings
from collections import Counter
from contextlib import nullcontext
+from .._utils import set_module
from . import numeric as sb
from . import numerictypes as nt
from numpy.compat import os_fspath
-from numpy.core.overrides import set_module
from .arrayprint import _get_legacy_print_mode
# All of the functions allow formats to be a dtype