summaryrefslogtreecommitdiff
path: root/numpy/lib/utils.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2020-05-19 10:16:50 +0100
committerEric Wieser <wieser.eric@gmail.com>2020-05-19 10:16:50 +0100
commitc4a1aef1c9d961907e346cab809e39b97172cadc (patch)
tree43db9cadab9de80f89a00eb9a5a73ca3cf7f1b3e /numpy/lib/utils.py
parent25f64902e9178bf476e2ce002985495ce56a7092 (diff)
downloadnumpy-c4a1aef1c9d961907e346cab809e39b97172cadc.tar.gz
BUG: np.info does not show keyword-only arguments
Using inspect.signature instead of `np.compat.getargspec` solves this problem. `inspect.signature` also handles stripping the `self` argument of methods for us.
Diffstat (limited to 'numpy/lib/utils.py')
-rw-r--r--numpy/lib/utils.py42
1 files changed, 7 insertions, 35 deletions
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py
index f233c7240..781ef47bc 100644
--- a/numpy/lib/utils.py
+++ b/numpy/lib/utils.py
@@ -9,9 +9,6 @@ from numpy.core.overrides import set_module
from numpy.core import ndarray, ufunc, asarray
import numpy as np
-# 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',
@@ -552,9 +549,12 @@ def info(object=None, maxwidth=76, output=sys.stdout, toplevel='numpy'):
file=output
)
- elif inspect.isfunction(object):
+ elif inspect.isfunction(object) or inspect.ismethod(object):
name = object.__name__
- arguments = formatargspec(*getargspec(object))
+ try:
+ arguments = str(inspect.signature(object))
+ except Exception:
+ arguments = "()"
if len(name+arguments) > maxwidth:
argstr = _split_line(name, arguments, maxwidth)
@@ -566,18 +566,10 @@ def info(object=None, maxwidth=76, output=sys.stdout, toplevel='numpy'):
elif inspect.isclass(object):
name = object.__name__
- arguments = "()"
try:
- if hasattr(object, '__init__'):
- arguments = formatargspec(
- *getargspec(object.__init__.__func__)
- )
- arglist = arguments.split(', ')
- if len(arglist) > 1:
- arglist[1] = "("+arglist[1]
- arguments = ", ".join(arglist[1:])
+ arguments = str(inspect.signature(object))
except Exception:
- pass
+ arguments = "()"
if len(name+arguments) > maxwidth:
argstr = _split_line(name, arguments, maxwidth)
@@ -605,26 +597,6 @@ def info(object=None, maxwidth=76, output=sys.stdout, toplevel='numpy'):
)
print(" %s -- %s" % (meth, methstr), file=output)
- elif inspect.ismethod(object):
- name = object.__name__
- arguments = formatargspec(
- *getargspec(object.__func__)
- )
- arglist = arguments.split(', ')
- if len(arglist) > 1:
- arglist[1] = "("+arglist[1]
- arguments = ", ".join(arglist[1:])
- else:
- arguments = "()"
-
- if len(name+arguments) > maxwidth:
- argstr = _split_line(name, arguments, maxwidth)
- else:
- argstr = name + arguments
-
- print(" " + argstr + "\n", file=output)
- print(inspect.getdoc(object), file=output)
-
elif hasattr(object, '__doc__'):
print(inspect.getdoc(object), file=output)