VS Code: How to auto refresh Pylint - python

I want the Pylint style suggestions to automatically update in VS code. E.g. if there is a style error, and I fix it I want it to automatically update, so I know if it is fixed.
Right now I have to save the file, wait a bit, and then see if it fixed the issue.
I am using python 2.7 (via Anaconda) pylint (1.6.4), and in VS Code I have Python 0.5.8 and Python for VSCode 0.2.3

You could turn auto save on.
See also this thread on reddit: https://www.reddit.com/r/vscode/comments/8ab5hi/does_python_linting_only_run_upon_save/

Related

Issue with new isort extension installed as from VS-Code Update October 2022 (version 1.73)

I'm using VS-Code version 1.73.1, with MS Python extension v2022.18.2, on Windows 10 Pro, Build 10.0.19045. After installing the October 2022 update of VS Code, when writing Python code I noticed nagging error diagnostics being issued by the isort extension about the import order of modules. Previously, I had never encountered such diagnostics.
I traced this behaviour back to the VS Code release notes for the Update October 2022. These announce the migration of VS Code to a new stand-alone isort extension, instead of the isort support built into the Python extension, by automatically installing it alongside the Python extension. When opening a file in which the imports do not follow isort standards, the extension is intended to issue an error diagnostic and display a Code Action to fix the import order.
Whilst the extension seems to work as intended, I found the issues described below:
1. Even after having executed the Code Action to fix the import order, a 'light-bulb' with the same error diagnostic and Code Action again pops up on moving the cursor to a new line of code.
2. The error diagnostic and Code Action 'light-bulb' are also displayed when moving the cursor to any new line of code, even when all lines of code in the file have been commented out; that is, effectively, there are no longer any import statements in the code, and therefore also nothing to be sorted.
I'd appreciate comments on whether this is a recognised issue in VS Code, and if so, whether any workarounds are available. It defeats the purpose of having an 'error lightbulb' pop up on every line of code, just to find a code action recommending to fix the import order, even when this requires no fixing.
I have opened this question on this forum as recommended on the GitHub 'Contributing to VS Code' page.
Upgrade the isort extension version to latest(v2022.8.0).

Installed Python 3.10.2 and now my Pip installs are not being found

Everything in my code was working perfectly fine up until I decided I wanted to utilize match-case in Python. Find out its only a thing in 3.10+, so I quickly install it and change it to be the interpreter in command palette.
Then I try to run my code same as before, and I'm not sure what changed but my Keyboard import is giving me 'Import "keyboard" could not be resolved'. Issues. The same issue was actually present as well with the 'from nis import match' module.
I installed keyboard initially using 'pip install keyboard' when running my 3.9 version, and legit everything was fine. This all started after I installed 3.10 (which I did from Pythons website yes); and I did add to PATH, but I dont think that would have any impact on my imports in VScode.
Confused as heck right now, please look at my screenshots for clearest explanation of what I'm facing.
Import could not be resolved
.
Module Not Found Error
.
pip3.10 show keyboard
.
My interpreter list from command palette
Any and all help appreciated, I'm extremely confused and think I've tried it all now
New Python versions use new site-packages folders. You need to reinstall everything. This is why poetry, pipenv, or requirements.txt are used
I think the linter-like extension/whatever Pylance is is the problem. Why? Because as we've tried, pip install keyboard and pip install --upgrade keyboard just confirm that the requirement is satisfied and the latest version of keyboard is already installed.
What I did was change Pylance's settings. Yes, it's not an actual error (with the code), but Pylance's problem. It just didn't see enough files in the keyboard package to satisfy its hunger, or Microsoft was just too lazy to pass more checks and update it accordingly, because however it happened, when I tried changing the setting to display an "error" at "missing imports" for fun, it didn't show errors or the default "warning" but "none", because I had run the file before I changed it back to display an error (maybe Pylance observed that when the file was run, there was no ModuleNotFoundError, and so stopped showing the warning).
I better shut now, because the setting I changed/overrode by adding it in settings.json is:
"python.analysis.diagnosticSeverityOverrides": {"reportMissingImports":"none"}
which is in:
{
...,
...,
...,
"python.analysis.diagnosticSeverityOverrides": {"reportMissingImports":"none"}
}
Here is a list of keys like "reportMissingImports" whose values you can change. These are the allowed values for the keys in python.analysis.diagnosticSeverityOverrides:
error (red squiggle)
warning (yellow squiggle)
information (blue squiggle)
none (disables the rule)
You would want to change their values only if you want to change their behaviour.
You can find settings.json by its path or by going to the settings GUI and clicking on any "Edit in settings.json" link-like button. You can also make settings.json open instead of the GUI by default.
Now, you won't see any more warnings when you import modules and can code without being anxious about the stupid warning.
Wow, So as it turns out, a solution I tried previously, to no avail is now working to solve this bizarre issue.
Simply put, I once again went to Command Palette (Ctrl+Shft+P), and looked through my interpreters I had to see what could be wrong.
Decided to click on the 'recommended' option I assumed I had been running this whole time. Turns out I was using this 'third' option as shown in the screenshot (the one not highlighted ofcourse); and it's the reason my module installs were being found on my machine, but not by the interpreter; as such giving me errors and not running the module for the program.
Simple error, but thanks to those who did help.

Visual Studio Code adding lines between code in Python terminal causing syntax errors

I'm running Python code in VS Code (1.28.2, with the Python, and Python Extension Pack extensions) and am using the 'Run Selection/Line in Python Terminal' (Shift+Enter) functionality to just run selected code in the Python terminal.
This has always worked well, but today I'm getting a new line added between each line of code in the terminal, i.e. if I ran:
import heapq
import pickle
the output in the terminal would be:
>>>import heapq
>>>
>>>import pickle
At first, this just seems like an annoyance, but any for loops or functions now come out with an indentation error...so essentially I can't successfully run any code.
I've tried re-installing VS Code as well as installing an older version of VS Code but all give the same problem.
It's so odd because it was working fine and then all of a sudden it changed. The only thing I can think of that has possibly changed is I installed the JSON Tools extension, but I don't believe this would change anything within Python (and I've tried uninstalling this, and not loading it again when reinstalling VS Code from scratch)
Any help would be greatly appreciated!
It's a bug that will be fixed in the 2018.9.1 release of the Python extension.

Emacs: Complete base class methods for Python

Is it possible to make either jedi.el or anaconda-mode complete base class methods? For example, when subclassing html.parser.HTMLParser I expect it to complete the following code at point (1) (base class has methods like handle_data or handle_starttag):
import html.parser
class MyParser(html.parser.HTMLParser):
def handle_ # (1)
I've done some research on this issue and I've found that it is implemented in the latest version of jedi (0.10.0). Unfortunately, this version is in development state right now and is not available from pip. However, many editors use 0.10.0: Atom, VsCode, and even jedi-vim from the author of jedi.
It's easy to update jedi's version in anaconda-mode: https://github.com/nightuser/anaconda-mode. The actual change is just a one line. The Python part of anaconda-mode must be reinstalled -- simply delete anaconda-mode directory. The default location is ~/.emacs.d/anaconda-mode for Emacs and ~/.emacs.d/.cache/anaconda-mode for Spacemacs.
upd: It seems that 0.10.0 will be released soon: https://github.com/davidhalter/jedi/issues/740 .
upd2: It was released and know everything works out of the box. Just remove anaconda-mode directory and it'll automatically install latest version.

Sublime Text 3 plugin Anaconda can't do multiple-line lint

I am using Sublime Text 3 (build 3047) using package control and the newest Anaconda plugin for python development. However I am facing a rather odd issue.
Using the default linter included in anaconda (not pylint), the plugin only displays the very first error it encounters.
So, if for example I am having errors in line 3, 5 and 10, only line number 3 will be highlighted. PEP8 is also currently disabled.
Is there any way to work around this problem and show all errors in a file at once?
Thank you.
There is no reason that you don't get any more errors linted in the buffer. The only thing that come to my mind is a possible incompatibility with any other ST3 plugin that you have installed as well.
You can do several things to try to figure out what can be wrong:
1) Take a look at the Sublime Text console to see if there are errors raised by Anaconda or other plugin
2) Take a look at your Anaconda JsonServer logs, you can fin them on: $HOME/Library/Caches/Jedi on Mac OS X, $HOME/.cache/jedi on GNU/Linux or %APP_DATA%\Jedi\Jedi on Windows.
You can get some support as well just joining the Anaconda mailing list at https://groups.google.com/forum/#!forum/anaconda-st3-plugin or just opening a new ticket in the project GitHub site: https://github.com/DamnWidget/anaconda/issues

Categories