spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.21k stars 1.59k forks source link

Docstring only works for functions and in the first line #17495

Open Holzhauer opened 2 years ago

Holzhauer commented 2 years ago

Description

What steps will reproduce the problem?

The menu entry "Generate docstring" is disabled. The same is true when placing the cursor at the end of a multiline-function-header.

This is not intuitive. At least, it should be documented well.

Versions

Dependencies

# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  2.0.0 (OK)
cookiecutter >=1.6.0          :  1.7.3 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.6.0;<8.0.0        :  7.31.1 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.1 (OK)
jellyfish >=0.7               :  0.9.0 (OK)
jsonschema >=3.2.0            :  4.4.0 (OK)
keyring >=17.0.0              :  23.0.1 (OK)
nbconvert >=4.0               :  6.4.1 (OK)
numpydoc >=0.6.0              :  1.2 (OK)
parso >=0.7.0;<0.9.0          :  0.8.3 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.9.0 (OK)
pygments >=2.0                :  2.7.1 (OK)
pylint >=2.5.0                :  2.12.2 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.3.2;<1.4.0          :  1.3.3 (OK)
pylsp_black >=1.0.0           :  1.1.0 (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.2.1 (OK)
qtawesome >=1.0.2             :  1.0.2 (OK)
qtconsole >=5.2.1;<5.3.0      :  5.2.2 (OK)
qtpy >=1.5.0                  :  1.9.0 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=49.6.0           :  52.0.0 (OK)
sphinx >=0.6.6                :  3.5.4 (OK)
spyder_kernels >=2.2.1;<2.3.0 :  2.2.1 (OK)
textdistance >=4.2.0          :  4.2.2 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.6 (OK)
xdg >=0.26                    :  0.27 (OK)
zmq >=17                      :  22.3.0 (OK)

# Optional:
cython >=0.21                 :  None (NOK)
matplotlib >=2.0.0            :  3.3.4 (OK)
numpy >=1.7                   :  1.19.5 (OK)
pandas >=1.1.1                :  1.4.0 (OK)
scipy >=0.17.0                :  None (NOK)
sympy >=0.7.3                 :  None (NOK)
dalthviz commented 2 years ago

Hi @Holzhauer thank you for the feedback! I was able to reproduce this (the entry in the context menu being disabled). I think the functionality only covers functions so probably we should change the name of the entry to something like Generate function doctring.

Also, as a workaround for the entry being disabled you can generate the docstring using the shortcut Ctrl+Alt+D (works for both single line function definitions and multiline function definitions):

docstring

Holzhauer commented 2 years ago

Hi @dalthviz, thanks! Three issues: 1) I realised that Ctrl+Alt+D does not work when the last line of the multiline-header is not intended, so it doesn't work for

    def test(a,
             b,
             c
    ): 

2) Ctrl+Alt+D does not work when the cursor is in the last line of the multiline-header - it needs to be in the next line (for single line header it works when the cursor is in that line). 3) I'd consider it a bug that the menu entry is disabled when the shortcut works.

dalthviz commented 2 years ago

Thank you for the new info @Holzhauer ! We will try to implement fixes for those things in a future release :+1: