diff options
Diffstat (limited to 'numpy/lib/utils.py')
-rw-r--r-- | numpy/lib/utils.py | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 519d0e9b9..97b93cace 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -9,6 +9,9 @@ import warnings from numpy.core.numerictypes import issubclass_, issubsctype, issubdtype from numpy.core import ndarray, ufunc, asarray +# getargspec and formatargspec were removed in Python 3.6 +from numpy.compat import getargspec, formatargspec + __all__ = [ 'issubclass_', 'issubsctype', 'issubdtype', 'deprecate', 'deprecate_with_doc', 'get_include', 'info', 'source', 'who', @@ -93,7 +96,7 @@ class _Deprecate(object): def newfunc(*args,**kwds): """`arrayrange` is deprecated, use `arange` instead!""" - warnings.warn(depdoc, DeprecationWarning) + warnings.warn(depdoc, DeprecationWarning, stacklevel=2) return func(*args, **kwds) newfunc = _set_function_name(newfunc, old_name) @@ -149,7 +152,7 @@ def deprecate(*args, **kwargs): >>> olduint(6) /usr/lib/python2.5/site-packages/numpy/lib/utils.py:114: DeprecationWarning: uint32 is deprecated - warnings.warn(str1, DeprecationWarning) + warnings.warn(str1, DeprecationWarning, stacklevel=2) 6 """ @@ -238,10 +241,10 @@ def byte_bounds(a): def who(vardict=None): """ - Print the Numpy arrays in the given dictionary. + Print the NumPy arrays in the given dictionary. If there is no dictionary passed in or `vardict` is None then returns - Numpy arrays in the globals() dictionary (all Numpy arrays in the + NumPy arrays in the globals() dictionary (all NumPy arrays in the namespace). Parameters @@ -390,9 +393,9 @@ def _info(obj, output=sys.stdout): Parameters ---------- - obj: ndarray + obj : ndarray Must be ndarray, not checked. - output: + output Where printed output goes. Notes @@ -531,7 +534,7 @@ def info(object=None, maxwidth=76, output=sys.stdout, toplevel='numpy'): elif inspect.isfunction(object): name = object.__name__ - arguments = inspect.formatargspec(*inspect.getargspec(object)) + arguments = formatargspec(*getargspec(object)) if len(name+arguments) > maxwidth: argstr = _split_line(name, arguments, maxwidth) @@ -546,8 +549,8 @@ def info(object=None, maxwidth=76, output=sys.stdout, toplevel='numpy'): arguments = "()" try: if hasattr(object, '__init__'): - arguments = inspect.formatargspec( - *inspect.getargspec(object.__init__.__func__) + arguments = formatargspec( + *getargspec(object.__init__.__func__) ) arglist = arguments.split(', ') if len(arglist) > 1: @@ -589,8 +592,8 @@ def info(object=None, maxwidth=76, output=sys.stdout, toplevel='numpy'): print("Instance of class: ", object.__class__.__name__, file=output) print(file=output) if hasattr(object, '__call__'): - arguments = inspect.formatargspec( - *inspect.getargspec(object.__call__.__func__) + arguments = formatargspec( + *getargspec(object.__call__.__func__) ) arglist = arguments.split(', ') if len(arglist) > 1: @@ -619,8 +622,8 @@ def info(object=None, maxwidth=76, output=sys.stdout, toplevel='numpy'): elif inspect.ismethod(object): name = object.__name__ - arguments = inspect.formatargspec( - *inspect.getargspec(object.__func__) + arguments = formatargspec( + *getargspec(object.__func__) ) arglist = arguments.split(', ') if len(arglist) > 1: @@ -643,7 +646,7 @@ def info(object=None, maxwidth=76, output=sys.stdout, toplevel='numpy'): def source(object, output=sys.stdout): """ - Print or write to a file the source code for a Numpy object. + Print or write to a file the source code for a NumPy object. The source code is only returned for objects written in Python. Many functions and classes are defined in C and will therefore not return @@ -976,7 +979,7 @@ def _getmembers(item): import inspect try: members = inspect.getmembers(item) - except AttributeError: + except Exception: members = [(x, getattr(item, x)) for x in dir(item) if hasattr(item, x)] return members @@ -1011,8 +1014,9 @@ class SafeEval(object): """ def __init__(self): + # 2014-10-15, 1.10 warnings.warn("SafeEval is deprecated in 1.10 and will be removed.", - DeprecationWarning) + DeprecationWarning, stacklevel=2) def visit(self, node): cls = node.__class__ |