Python Visual Studio Code autoDocstring Configuration - python

Goal: generate docstring in vscode for Python automatically and format the generated docstring to my liking.
Solution: I installed the autoDocstring extension.
Problem: I don't know how to get the generated docstring to be formatted the way I want it. In the description under the "Extension Settings" heading, it seems to suggest that you can change the default format with the "autoDocstring.docstringFormat" setting. My question is, how does one configure that setting? I've looked around and cannot find a solution.

You have to go to:
File > Preferences > Settings in Windows/Linux
Code > Preferences > Settings in Mac
Then choose at the right side of the open document if you want to change the configuration for all the user sessions or only this workspace.
The workspace case would be:
{
"autoDocstring.docstringFormat": "sphinx"
}
When moving the mouse around the option, a little pencil appears that shows all the accepted values for the option.

This answer is almost the same as PyCharm generates on vscode with this shortcut
ctrl+sfhit+2
{
"autoDocstring.docstringFormat": "sphinx"
}

Related

Why is Pycharm not highlighting TODO's?

In my settings, I have the TODO bound to highlight in yellow, yet in the actual code it does not highlight. Here is a screenshot of my settings: Editor -> TODO
Does anyone know how to fix this?
EDIT: I even tried re-installing Pycharm and I still have the issue.
EDIT 2: In the TODO Window, it is saying "0 TODO items found in 0 files". I believe this means it is looking in the wrong files to check for TODO items. However, when I try to find TODO items in "this file" it still doesn't work. Does anyone know why this is?
Go to Preferences (or Settings), Project Structure, and make sure the folder with your files is not in the "Excluded" tab's list.
Click the folder you want to include and click on the "Sources" tab. Click Apply, then OK!
It should work.
I recently updated PyCharm Professional and my TODOs no longer worked. I went into settings and changed the alert icon, then saved, and retyped them and they worked. I imagine for my case, there was a delay in the new version picking them up. Might just need to retype them to get them working again, though the reboot should have addressed this.
Not sure if your pattern is causing this, but mine is set up like so, with two separate patterns:
\btodo\b.*
\bfixme\b.*
Neither is case sensitive, BTW...
Perhaps try some other patterns to see if you can get those to work.
I think the problem for me was the same as explained by #theBrownCoder but I couldn't find the project structure settings.
Apart from not showing TODO's another symptom was impossibility to go to function definitions defined in other files and inability to rename python files with the error: "Selected element is used from non-project files. These usages won't be renamed."
Googling for this the solution that worked for me was to delete the .idea folder (make sure to back it up just in case, you will lose the configurations).
I had the exact same problem, and the solution suggested by theBrownCoder worked perfectly.
For those who cannot find which menu theBrownCoder is referring to, go to File > Settings > Project: "Title of Project" > Project Structure.
It is in the dropdown of Project in Settings where you can also select your Python interpreter.
It might be the file type.
Right click, Override File Type.
I had this issue with a text file and it's copy, only the first one would use #TODO

How to setup vscode settings for Python formatter?

Somehow my formatter isn't working. I pip installed yapf , but when I do Ctrl+Shift+P -> Format Document or Shift + Alt + F on a selected code, It doesn't change. I heard it auto formats on save, but that didn't work either.
I am trying to follow the guide here.
It mentions I should edit this part in the settings
"python.formatting.yapfArgs": ["--style", "{based_on_style: chromium, indent_width: 20}"],
But when I search this, this is the only thing I see
What I am trying to do at the moment is set the indent to 4 spaces, and also adjust the max line length.
This is what my settings look like for formatting
It seems in the preference you have not set the correct "provider" for the formatting
You can also check for the file C:\Users\\AppData\Roaming\Code\User\settings.json (if you want to change globally) or \.vscode\settings.json (if you want to change for the current workspace only).
Hope that helps.

Can I use another shortcut for auto import in pycharm?

The shortcut Alt+Enter is intercepted by my window manager(i3) to create a new terminal, so the default shortcut of auto import(which is also Alt + Enter) doesn't work in pycharm. Can I use another shortcut to do the auto import? It's really a pain to import the required package manually every time.
Go to
File > Settings > Keymap
And remap your auto-import to a different key or combination of keys. The keymap should be labeled under
Other > Show Intention Actions
You can search for it in the search bar.
Google is your friend and can come in handy when asking simple questions like these, so please abstain from asking questions that can be easily found online.

Change highlighting setting for every file (by default) in PyCharm CE

I just started using PyCharm as my IDE for Python. At the moment whenever I open a new .py file, I have to go to Code -> Configure Current File Analysis..., and then change the highlighting to syntax (preference) for every individual .py file.
Is there a way to change this for every file automatically, by default?
First post on stackoverflow by the way.
Thanks!
If you prefer not to see PyCharm's code inspections, I would suggest creating a new inspections profile that does no inspections. To do that, go to the Code -> Configure Current File Analysis dialog like you have been, but this time click on the Configure inspections link. At the top, click the "Manage" dropdown and copy the current profile into a new profile which you'll name "No inspections". Then uncheck everything, save the new inspections profile, and you'll be done. All new .py files should now be created under your "No inspections" profile.
Note that as far as I can tell, the inspection settings get saved per-project, rather than as a global setting. But changing the inspection profile once per project shouldn't be too much of a hassle.

python IDE for auto-complete Docstring

I am looking for a Python IDE which can generate the docstrings framework for me automatically.
For example:
def GetTextByCtrlName(self, _hwnd, _ctrName):
'''
#desc:
#param:
_hwnd
_ctrName
'''
Then I can just fill the corresponding content.
PyCharm has supported this since version 1.5.
First, configure the format you want the docstring to be generated. Hit CTRL+ALT+S (on Windows), select the format in Project Settings > Python Integrated Tools.
Your choices are plain, Epydoc or reStructuredText
Once that is configured, make sure your cursor is on the method name and press Alt+Enter.
You could use a tool like Sphinx. It's designed to specifically document python code, although it doesn't offer a friendly IDE integration.

Categories

Resources