I have reinstalled my PC and get crazy about initialising VScode correctly.
I want to use syntax highlighting in Python, I use tabs instead of space and I don't want to see pep8 warnings.
After ours of debugging, I dont have syntax highlighting, errors due to tabs and I see all pep8 warnings.🙈
I have installed Python and Pylance as extensions and currently, my settings.json looks like this:
{
"[python]": {
"editor.insertSpaces": true,
"editor.tabSize": 4
},
"python.linting.enabled": false,
"files.exclude": {
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true
},
"java.semanticHighlighting.enabled": true,
"terminal.integrated.enableMultiLinePasteWarning": false
}
Is there anybody who can knows what to do?
Edit: After reloading, the messages about space vs tabs have disappeared.
If you want to ignore the messages prompted by the pylint you can add this in the settings.json:
"python.linting.pylintArgs": ["--disable", "C"],
And it means this:
Convention (C)
Refactor (R)
Warning (W)
Error (E)
Fatal (F)
And you can do it like this to disable multi types of the message:
"python.linting.pylintArgs": ["--disable", "C,R,W"],
Related
I'm having an issue regarding Visual Studio Code OneDark Pro theme. I would like to change the color of variables (only variables I declare, not method calls, etc. but when I try to do this using
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "source.python",
"settings": {
"foreground": "#E06C75"
}
}
]
}
I get this (I wrote a code sample to illustrate what is happening):
As you can see, colons are in red, every variables even the "for i in..." and the full "os.system.getcwd()" are in red.
I only want the variables I declare to be in red. How can I do that ?
Thank you in advance!
You can modify the editor color in VSCode with Syntax Highlighting like this:
"editor.tokenColorCustomizations": {
"variables": "#c3e01f"
},
Or the Semantic Highlighting like this:
"editor.semanticTokenColorCustomizations": {
"[The Theme Name]": {
"rules": {
"variable.declaration": "#c3e01f"
}
}
},
If you don't know the scope of the object which you want to customize, you can use the built-in tool in VSCode: Developer: Inspect Editor Tokens and Scopes(Command Palette).
And I think this article and this one can help you understand the color customization in the VSCode.
In VSCode's settings.json, I enabled PyLance's type checking:
"python.analysis.typeCheckingMode": "basic"
This shows all typing issues as errors (underlined in red), even when code is valid Python and will run with no issue.
For example, the following code is valid Python, and works:
if 4 % 2 == 0:
a = 3
print(a)
...but PyLance shows an error because of the case where a is unbound:
I want to only mark as "errors" the actual syntax errors that will be rejected by Python, and mark everything else as warnings. I can do it for one category with:
"python.analysis.diagnosticSeverityOverrides": {
"reportGeneralTypeIssues": "warning"
}
How can I do that for all such errors?
Sorry, but I am afraid you only can override the diagnostic severity explicitly one by one.
Such as set "reportUnboundVariable": "warning", to change the error to warning which you have metioned in the above.
But, there is no way to change all of them one time.
Problem: VS Code is not underlining errors (with wavy red underlining) as it used to.
Problem exists for me and my friend (macOS and Windows)
Linter: mypy
settings.json:
{
"python.pythonPath": "/Users/username/.pyenv/versions/3.8.5/bin/python",
"python.linting.pylintEnabled": false,
"python.linting.mypyEnabled": true,
"python.linting.enabled": true
}
After running the script VS will underline found errors, but still wont underline any newly written errors.
When typing anything in the script, OUTPUT:python shows the following (or simular), which i dont understand and am not sure if its relevant:
Error 2020-11-09 20:20:07: stderr jediProxy Error (stderr) /Users/username/.vscode/extensions/ms-python.python-2020.10.332292344/pythonFiles/completion.py:584: DeprecationWarning: Deprecated since version 0.16.0. Use Script(...).get_names instead.
jedi.api.names(
Error 2020-11-09 20:20:27: stderr jediProxy Error (stderr) /Users/username/.vscode/extensions/ms-python.python-2020.10.332292344/pythonFiles/completion.py:592: DeprecationWarning: Providing the line is now done in the functions themselves like `Script(...).complete(line, column)`
script = jedi.Script(
/Users/username/.vscode/extensions/ms-python.python-2020.10.332292344/pythonFiles/completion.py:592: DeprecationWarning: Deprecated since version 0.17.0. Use the project API instead, which means Script(project=Project(dir, sys_path=sys_path)) instead.
script = jedi.Script(
Error 2020-11-09 20:20:27: stderr jediProxy Error (stderr) /Users/username/.vscode/extensions/ms-python.python-2020.10.332292344/pythonFiles/completion.py:105: DeprecationWarning: Deprecated since version 0.16.0. Use Script(...).get_signatures instead.
call_signatures = script.call_signatures()
/Users/username/.vscode/extensions/ms-python.python-2020.10.332292344/pythonFiles/completion.py:230: DeprecationWarning: Deprecated since version 0.16.0. Use Script(...).complete instead.
completions = script.completions()
Thanks for helping!
I've been searching online for quite a while now and can't seem to find a solution for my problem. I installed Pylance (the newest Microsoft interpreter for Python) and can't seem to disable linting at all. I've tried a lot of options but none worked. Here's a screenshot of how annoying linting is in my code now.
Here's how my VSCode Settings file looks like:
{
// "python.pythonPath": "C://Anaconda3//envs//py34//python.exe",
// "python.pythonPath": "C://Anaconda3_2020//python.exe",
// "python.pythonPath": "C://Anaconda3_2020_07//python.exe",
"python.pythonPath": "C://Anaconda3//python.exe",
"python.analysis.disabled": [
"unresolved-import"
],
"editor.suggestSelection": "first",
"editor.fontSize": 15,
"typescript.tsserver.useSeparateSyntaxServer": false,
"workbench.colorTheme": "Monokai ST3",
"workbench.colorCustomizations": {
"editor.background": "#000000",
"statusBar.background": "#000000",
"statusBar.noFolderBackground": "#212121",
"statusBar.debuggingBackground": "#263238"
},
"window.zoomLevel": 0,
"editor.renderLineHighlight": "none",
"editor.fontFamily": "Meslo LG L",
"editor.tabCompletion": "on",
"editor.parameterHints.enabled": true,
"python.terminal.executeInFileDir": true,
"python.terminal.launchArgs": [
"-u"
],
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"editor.lineHeight": 0,
"workbench.editor.scrollToSwitchTabs": true,
"python.autoComplete.showAdvancedMembers": false,
"python.languageServer": "Pylance",
"python.linting.enabled": false,
"python.linting.pylintEnabled": false,
"python.linting.lintOnSave": false,
"python.linting.flake8Enabled": false,
"python.linting.mypyEnabled": false,
"python.linting.banditEnabled": false,
"python.linting.pylamaEnabled": false,
"python.linting.pylintArgs": [
"--unsafe-load-any-extension=y",
"--load-plugin",
"pylint_protobuf",
"--disable=all",
"--disable=undefined-variable",
],
"python.linting.mypyArgs": [
"--ignore-missing-imports",
"--follow-imports=silent",
"--show-column-numbers",
"--extension-pkg-whitelist=all",
"--disable=all",
"--disable=undefined-variable",
],
}
Any thoughts?
Any help is much appreciated.
You can disable the language server with:
"python.languageServer": "None"
I was able to click on the Extensions within VSC, search for Pylance and then right click to uninstall. You can also disable.
One way of getting rid of those warnings in your picture is to disable the Pylance by setting "python.languageServer": "None"(already mentioned by the accepted answer).
But you are basically disabling the language server which means you will lose all the help from Pylance. I don't think this is what you want.
Instead you can exclude some paths and those won't get type-checking at all. I usually do it for Python's standard library.
In previous versions of Pylance, you could create a pyrightconfig.json(Pylance is built on top of Pyright, that's why) in the root of your workspace and put this inside(for more information - click):
{
"ignore": [
"path to your third-party package or stdlib or ..."
],
}
But since now (October 2022), you can directly set it in settings.json:
"python.analysis.ignore": ["path to your third-party package or stdlib or ...", ]
Remember you can use wild-cards in paths. This way your custom modules are only getting checked.
If you want to completely disable type-checking:
"python.analysis.typeCheckingMode": "off"
Disabling language server works as answered by maxm. This will also disable other features.
Instead, just ignore the warnings and errors of pylance by setting below in settings.json of .vscode.
"python.analysis.ignore": [
"*"
]
The other features will be present with out disabling pylance.
Although I seem to have configured both linitng and formatting properly, the linting runs but the black formatting does not.
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": [
"--max-line-length=110"
],
"python.linting.lintOnSave": true,
"python.formatting.provider": "black",
"python.formatting.blackPath": "/usr/local/bin/black",
"python.formatting.blackArgs": [
"--line-length",
"110"
],
"editor.formatOnSave": true,
I have checked, that black is properly configured and I can run the formatting from the command-line without issues.
But when saved in the IDE, black does not format the file. It also does not complain, there are no error-messages that pop up and nothing showing up in the logs. It just does not run the formatting at all.
I am running this insisde a docker-container using remote-editing: not sure, if this makes a difference.
The black-version is:
black>=19.3b0
and the vscode-version is 1.36.1.
Thx for any help, as right now I am pretty clueless, why the black-formatting does not run...
The line argument for black is wrong, it should be
--line-length=120
according to https://stackoverflow.com/a/58048911/4435175.
Late answer, in case it helps anybody. I had the same problem and resolved it as below
I needed to have this line in user settings.json
"editor.defaultFormatter": "ms-python.python"
Otherwise, I guess, the formatting was overwritten by my default formatting option which was
"editor.defaultFormatter": "esbenp.prettier-vscode",
So my overall settings for formatting related stuff were as below
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "ms-python.python"
},
"[javascript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"python.formatting.provider": "black",
"python.formatting.blackPath": "/home/<user>/anaconda3/bin/black",
This line "editor.defaultFormatter": "ms-python.python" could also have been activated as below from VS-Code command-pallette (Ctrl + shift + P).
Format Document with > Configure Default formatter > Select Python
But here is a wild guess: I started the dockerd manually from the command-line using sudo: This gave me all kind of weird issues (files created from inside the container e.g. migrations or cache-files ended up being owned by root. I recently moved the dockerd into a service, now suddenly black is running on save. The root of all evil could have been rights-issues, that come from the fact that the dockerd was run as sudo and not as a service.
I add the blackPath:
"python.formatting.provider": "black",
"python.formatting.blackPath": "C:/conda/Scripts/black.exe",
and solve this issue.
I use miniconda.