Skip to content

Commit

Permalink
MAINT: Cleanup code after dropping Python 3.7.
Browse files Browse the repository at this point in the history
  • Loading branch information
charris committed Aug 16, 2021
1 parent 9a176d0 commit dfc25f5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 76 deletions.
94 changes: 39 additions & 55 deletions numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,70 +270,54 @@
oldnumeric = 'removed'
numarray = 'removed'

if sys.version_info[:2] >= (3, 7):
# module level getattr is only supported in 3.7 onwards
# https://www.python.org/dev/peps/pep-0562/
def __getattr__(attr):
# Warn for expired attributes, and return a dummy function
# that always raises an exception.
try:
msg = __expired_functions__[attr]
except KeyError:
pass
else:
warnings.warn(msg, DeprecationWarning, stacklevel=2)

def _expired(*args, **kwds):
raise RuntimeError(msg)

return _expired

# Emit warnings for deprecated attributes
try:
val, msg = __deprecated_attrs__[attr]
except KeyError:
pass
else:
warnings.warn(msg, DeprecationWarning, stacklevel=2)
return val

# Importing Tester requires importing all of UnitTest which is not a
# cheap import Since it is mainly used in test suits, we lazy import it
# here to save on the order of 10 ms of import time for most users
#
# The previous way Tester was imported also had a side effect of adding
# the full `numpy.testing` namespace
if attr == 'testing':
import numpy.testing as testing
return testing
elif attr == 'Tester':
from .testing import Tester
return Tester

raise AttributeError("module {!r} has no attribute "
"{!r}".format(__name__, attr))

def __dir__():
return list(globals().keys() | {'Tester', 'testing'})
def __getattr__(attr):
# Warn for expired attributes, and return a dummy function
# that always raises an exception.
try:
msg = __expired_functions__[attr]
except KeyError:
pass
else:
warnings.warn(msg, DeprecationWarning, stacklevel=2)

else:
# We don't actually use this ourselves anymore, but I'm not 100% sure that
# no-one else in the world is using it (though I hope not)
from .testing import Tester
def _expired(*args, **kwds):
raise RuntimeError(msg)

# We weren't able to emit a warning about these, so keep them around
globals().update({
k: v
for k, (v, msg) in __deprecated_attrs__.items()
})
return _expired

# Emit warnings for deprecated attributes
try:
val, msg = __deprecated_attrs__[attr]
except KeyError:
pass
else:
warnings.warn(msg, DeprecationWarning, stacklevel=2)
return val

# Importing Tester requires importing all of UnitTest which is not a
# cheap import Since it is mainly used in test suits, we lazy import it
# here to save on the order of 10 ms of import time for most users
#
# The previous way Tester was imported also had a side effect of adding
# the full `numpy.testing` namespace
if attr == 'testing':
import numpy.testing as testing
return testing
elif attr == 'Tester':
from .testing import Tester
return Tester

raise AttributeError("module {!r} has no attribute "
"{!r}".format(__name__, attr))

def __dir__():
return list(globals().keys() | {'Tester', 'testing'})

# Pytest testing
from numpy._pytesttester import PytestTester
test = PytestTester(__name__)
del PytestTester


def _sanity_check():
"""
Quick sanity checks for common bugs caused by environment.
Expand Down
5 changes: 0 additions & 5 deletions numpy/core/src/multiarray/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
#include "structmember.h"

#include <pymem.h>
/* public api in 3.7 */
#if PY_VERSION_HEX < 0x03070000
#define PyTraceMalloc_Track _PyTraceMalloc_Track
#define PyTraceMalloc_Untrack _PyTraceMalloc_Untrack
#endif

#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
Expand Down
18 changes: 2 additions & 16 deletions numpy/tests/test_public_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,8 @@ def test_numpy_namespace():
'show_config': 'numpy.__config__.show',
'who': 'numpy.lib.utils.who',
}
if sys.version_info < (3, 7):
# These built-in types are re-exported by numpy.
builtins = {
'bool': 'builtins.bool',
'complex': 'builtins.complex',
'float': 'builtins.float',
'int': 'builtins.int',
'long': 'builtins.int',
'object': 'builtins.object',
'str': 'builtins.str',
'unicode': 'builtins.str',
}
allowlist = dict(undocumented, **builtins)
else:
# after 3.7, we override dir to not show these members
allowlist = undocumented
# We override dir to not show these members
allowlist = undocumented
bad_results = check_dir(np)
# pytest gives better error messages with the builtin assert than with
# assert_equal
Expand Down

0 comments on commit dfc25f5

Please sign in to comment.