When writing an array (numpy) in a docstring that must (should) break lines, one has the option of meeting the needs of unit testing OR formatted text in Spyder. This is likely a bug (shortcoming) of the rst interpreter, not Spyder proper, but I don't know how to connect through to the right place.
What steps will reproduce the problem?
>>> A = np.array([[ 0., 0. , 1. , 0. ],\
[ 0., 0. , 0. , 1. ],\
[-1.4, 1.2, -0.0058, 0.0014],\
[ 0.8, -1.4, 0.0016, -0.0038]])
What is the expected output? What do you see instead?
The formatting doesn't recognize the line break. It results in one giant long line.
Using \ fixes this, but breaks unit testing (pytest).
Please provide any additional information below
Please go to the menu entry Help > Optional Dependencies
(or
Help > Dependencies
), press the button Copy to clipboard
and paste the contents below:
IPython >=4.0 : 6.2.1 (OK)
cython >=0.21 : 0.26.1 (OK)
jedi >=0.9.0 : 0.11.0 (OK)
nbconvert >=4.0 : 5.3.1 (OK)
numpy >=1.7 : 1.13.3 (OK)
pandas >=0.13.1 : 0.21.0 (OK)
psutil >=0.3 : 5.4.0 (OK)
pycodestyle >=2.3: 2.3.1 (OK)
pyflakes >=0.6.0 : 1.6.0 (OK)
pygments >=2.0 : 2.2.0 (OK)
pylint >=0.25 : 1.7.4 (OK)
qtconsole >=4.2.0: 4.3.1 (OK)
rope >=0.9.4 : 0.10.5 (OK)
sphinx >=0.6.6 : 1.6.3 (OK)
sympy >=0.7.3 : 1.1.1 (OK)
Just FYI, sphinx
is the package that handles building/showing the help docs, so that's probably where you'll want to submit a bug I would think unless this is a problem specific to Spyder.
Will do. I'll close and repost there.
This is easily resolved by using ... at the start of the continuation lines.
>>> A = np.array([[ 0., 0. , 1. , 0. ],
... [ 0., 0. , 0. , 1. ],
... [-1.4, 1.2, -0.0058, 0.0014],
... [ 0.8, -1.4, 0.0016, -0.0038]])
Ah, I knew there had to be a reason I've never had this problem in my own code without using \ ... and here I thought I was just using them for style points; didn't know docstrings would break without them. Glad you got it fixed easily.
I had to post the answer here, though. This way I can search and find it the next time I forget. At my age... that's likely tomorrow!
Thanks! I'm already a scatterbrained scientist at the age of 22...can't imagine what it'll be like when I'm older, heh.
Stay scatterbrained. It keeps your mind alive. Most my age have given up any technical skills. I refuse to, even though my job would allow. It's fun to stay current!
Most helpful comment
This is easily resolved by using ... at the start of the continuation lines.