Spyder: Line breaks in docstring formatting conflict with unit testing requirements

Created on 25 Nov 2017  路  7Comments  路  Source: spyder-ide/spyder

Description of your problem

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?

  1. Insert the following as a docstring:
    temp.py.txt
>>> 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]])
  1. Get help in Spyder
  2. Yuck

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

Versions and main components

  • Spyder Version: 4.0.0 and 3.2.4
  • Python Version: 3.6.3
  • Qt Version: 5.9.2
  • PyQt Version: 5.9.1
  • Operating system: Darwin (10.13.1)

Dependencies

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)

Most helpful comment

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]])

All 7 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spyder-bot picture spyder-bot  路  3Comments

spyder-bot picture spyder-bot  路  3Comments

SapnaSM picture SapnaSM  路  3Comments

goanpeca picture goanpeca  路  3Comments

impact27 picture impact27  路  3Comments