Spyder: Can't turn off docstring auto-generate

Created on 4 Jul 2020  路  14Comments  路  Source: spyder-ide/spyder

Problem Description

I have Spyder installed via Anaconda. I had an installation of 4.1.2 working satisfactorily in my base anaconda environment. I made a new environment for a project, which ended up installing 4.1.3.

It seemed to be working fine until I started writing some code in it and every time I would def something(): and hit ''' on the next line, if I hit enter next (as one does), Spyder would automatically produce an unwanted docstring of several lines.

I spent about 2 hours looking for a way to turn this off. I can't find one. It's critically annoying.

I finally decided, since my install in base environment wasn't giving me any trouble, that I must have messed up a setting, and told Spyder to revert to default settings. Big mistake! Anaconda doesn't actually make two separate installs of Spyder, settings and active projects, etc are shared between both environments (which I also don't like, but that's a separate issue). I lost all my settings in the base environment too, and now it's doing the same thing (yet still on 4.1.2).

If I type it fast enough, it doesn't populate, but if I hesitate at all between the last ' and hitting enter, BAM, there it is.

What steps reproduce the problem?

  1. Run Spyder
  2. def something():, hit enter, ''', hit enter.

What is the expected output? What do you see instead?

Only what I typed, not a 4 line useless docstring.

An option to either increase the wait time, or turn it off completely, would be ideal.

I don't understand why I didn't have this problem on my previous environment, and now I do. Downgrading the environment's install to 4.1.2 didn't help, and the base environment now also has this problem after resetting my settings. :(

Edit: Alternatively, the ability to customize the output would make it actually useful to me; I'd use it if all it produced was something like this:

def something():
    '''

    '''

Versions

  • Spyder version: 4.1.3
  • Python version: Python 3.8.1 64-bit | Qt 5.9.7 | PyQt5 5.9.2 | Darwin 19.4.0

  • Operating System name/version: OSX Catalina 10.15.4

Editor Ux-usability Enhancement

All 14 comments

I second this!

This is related to #10622 and more specifically to https://github.com/spyder-ide/spyder/issues/10622#issuecomment-556080361.

I agree that this can be annoying. How about doing something similar as proposed in #12728? That is, have Enter insert a new line, as normal, and use Tab to activate the "Generate docstring" function. To me, the docstring auto-generate feels similar to auto-complete.

Hey @ardunster , sorry for the trouble; sounds really frustrating. As it stands, you can avoid auto-generating the docstring by tapping escape (or any key except Enter) following typing triple quotes. However, I agree the UX needs to be better here. Based on what you've described, I propose the following three changes: The first one certainly, and either one or both of the last two, though @jitseniesen 's suggestion may be better than the second option as a more general solution.

  • Auto-docstring should not trigger on ''', only """, because per PEP 257, the Docstring standard, always use """triple double quotes""" around docstrings, not single as in your example.
  • We could have the "Generate docstring" option not selected by default in the completion popup so the user has to press down before pressing enter to confirm it while simply pressing enter inserts a newline, as used to be the case for completions with only one item. However, not sure how difficult this would be to implement, and the UI wouldn't be consistent with the completion popup; I think @jitseniesen 's suggestion of using Tab to either trigger or accept the Generate Docstring function would be much better (I'd much prefer the latter for discoverability).
  • Finally, we could add a checkbox to disable the popup in the docstring generation section of the Editor advanced settings (a None option in the Docstring type popup menu would be simpler but would also disable using the shortcut and the context menu to trigger it when desired). However, again, if we do the previous change I'm not sure this is really necessary.

@jnsebgosselin Yeah, that's exactly it. I did search for previous threads on the issue but my search-fu was not up to par in my frustration ;)
@jitseniesen Having it complete on Tab instead of Enter would work great. It would keep the option easily accessible when it's wanted, and avoid the accidental insertion when it's not; you're not likely to type ''' then Tab by accident.
@CAM-Gerlach Thanks for the reply. Sorry if I was pretty aggravated, it was driving me nuts and I was fighting with it and trying to turn it off and wasting a bunch of time on it when I'd really rather have been producing some code. I guess if I had known it wasn't possible to turn off I would have just dealt with it instead of fighting it, like I did after posting ;D Using Tab to accept the generation sounds like a very good change, to me. It doesn't bother me that it pops up, just that my usual, reasonable-to-me typing pattern auto generates something I don't want. I didn't realize PEP specified """ for docstrings, though; I'll have to check that out.

@ardunster No worries, it sounded annoying to begin with and I know I myself have been pretty upset in the past when my own heavily customized Spyder config got wiped due to one bug or another in the dev branch, to the point where I would just keep multiple backups all the time just in case. @juanis2112 is implementing a --safe-mode CLI option when launching Spyder that will start it in a clean config just for the current session, so you can see if a settings reset fixes an issue without actually having to wipe your config.

Sounds like we all agree using Tab instead of Enter to trigger docstring generation is the best UX here; I can go ahead and implement detecting only double quotes since that's easy but that change would probably be better done by one of the devs with more experience working on the completion popup dialog, so it can be consistent with how we do it elsewhere.

@CAM-Gerlach that safe mode option sounds like a fantastic addition. Guess in the meantime I'll find out how to backup my settings before I go messing with anything else ;) Thanks!

@ardunster I originally added it to the bootstrap.py script that launches Spyder in dev mode some years ago, but only now is it being added to Spyder itself. The easiest way to backup your entire config directory is just make a copy of it and name it something else, hehe (its located at ~/.spyder-py3). Spyder does store backups of your config, but if you manually wipe it they won't get preserved and I tend not to rely on it regardless.

How about adding "Plain" to docstring type?(like pycharm)

docstring

That would be a great option to have. I do think though that especially if we are going to make on the fly completion require tab instead of enter to complete, it would still be a good idea to do the same here since users may still want to generate full docstrings on demand, but just don't want it interfering with their workflow on the fly. But idk.

Maybe an option in settings as to what kind of docstring you want to generate when you hit tab to complete?

@ardunster So you mean separating the option for the dcostring type when hitting tab and the one when right-clicking a function name? I'm not sure if that's really a common enough usecase to justify the extra complexity of two very similar options, but idk.

No, I must have misunderstood something :) Maybe there's an option in place that I don't know about, or you were discussing a possibly planned option. I would expect the same behavior from 'Generate Docstring' whether I used tab to complete or right clicked on something to do so. I was just thinking that it would be nice to have options in preferences as to what kind of docstring would generate when you do either one.

@ardunster Oh, sorry about that! There is currently an option "Docstring Type" under Preferences > Editor > Advanced settings > Docstring type that lets you choose between Numpydoc, Googledoc and Sphinx for the autogenerated docstring. @ok97465 was proposing adding Plain to that list, which would just add the beginning and ending triple quotes to give you a simple docstring, as you want.

image

The thing with that as the only solution is that often you don't want a full docstring to be completed automatically as you type, but you do want to generate a full docstring on-demand sometimes, you wouldn't be able to do that seperately. Also, per PEP 257, the docstring standard, one-line docstrings should have the """ all on the same line, though in practice this isn't always done. I still think its a good idea to add that option, but IMO the main fix should still be what @jitseniesen suggested with Tab, especially if we're doing that with the other completion popups.

Oh, yeah, gotcha. I'd seen that preference but completely forgot because it didn't have the option I was looking for.... Oops. I definitely think the Tab to complete is the best most important thing to change in regards to this thread.

Was this page helpful?
0 / 5 - 0 ratings