diff options
author | Matti Picus <matti.picus@gmail.com> | 2021-11-25 00:42:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-25 00:42:11 +0200 |
commit | dcbbaa3c187491d2abcea2a53f1328af88fc337c (patch) | |
tree | 4ce1609832164ca0c45f604744f82dc9c34f87fb /numpy/lib/utils.py | |
parent | e94bbb87ba10ec2585f87af8e9a80afee2f89e04 (diff) | |
parent | 860c66c19866050bbf25f7f675ecff3ab88398e2 (diff) | |
download | numpy-dcbbaa3c187491d2abcea2a53f1328af88fc337c.tar.gz |
Merge pull request #20446 from abatomunkuev/issue#20423
BUG: Fixed output variable overriding in numpy.info()
Diffstat (limited to 'numpy/lib/utils.py')
-rw-r--r-- | numpy/lib/utils.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 1df2ab09b..c74ee127d 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -429,7 +429,7 @@ def _makenamedict(module='numpy'): return thedict, dictlist -def _info(obj, output=sys.stdout): +def _info(obj, output=None): """Provide information about ndarray obj. Parameters @@ -455,6 +455,9 @@ def _info(obj, output=sys.stdout): strides = obj.strides endian = obj.dtype.byteorder + if output is None: + output = sys.stdout + print("class: ", nm, file=output) print("shape: ", obj.shape, file=output) print("strides: ", strides, file=output) @@ -481,7 +484,7 @@ def _info(obj, output=sys.stdout): @set_module('numpy') -def info(object=None, maxwidth=76, output=sys.stdout, toplevel='numpy'): +def info(object=None, maxwidth=76, output=None, toplevel='numpy'): """ Get help information for a function, class, or module. @@ -496,7 +499,8 @@ def info(object=None, maxwidth=76, output=sys.stdout, toplevel='numpy'): Printing width. output : file like object, optional File like object that the output is written to, default is - ``stdout``. The object has to be opened in 'w' or 'a' mode. + ``None``, in which case ``sys.stdout`` will be used. + The object has to be opened in 'w' or 'a' mode. toplevel : str, optional Start search at this level. @@ -541,6 +545,9 @@ def info(object=None, maxwidth=76, output=sys.stdout, toplevel='numpy'): elif hasattr(object, '_ppimport_attr'): object = object._ppimport_attr + if output is None: + output = sys.stdout + if object is None: info(info) elif isinstance(object, ndarray): |