August 17, 2020

Visual Studio Code PyLint issue

Problem: For Visual Studio Code, valid Python code has red-squiggles.

 

Visual Studio Code is a great tool for python programming.  Recently, I found a strange issue: a valid python code line has red squiggles.  It is a method call of some package I installed, and VSC correctly pops up available methods for the package fine.  It's there, why red squiggle then?

This red squiggle is work of Linting telling me that something is wrong.  VSC supports different Lint programs, and PyLint is one of them that works for me the best. 

But this red squiggle for valid method -- this turns out to be a security feature: Pylint does not import non-stdlib C extensions as it is a security risk.

 

Solution:

Tell Pylint to load the extension anyways.

1. File → Preferences → Settings → User settings tab

2. Type in "python.linting.pylintArgs"  This will bring up Pylint Argument setting.

3. Click on "Add Item" button and add this line:

--unsafe-load-any-extension=y

All working well now.


ADDITION - Disable warnings

[1]

https://stackoverflow.com/questions/4341746/how-do-i-disable-a-pylint-warning

$ pylint --generate-rcfile > stndard.rc 

In [MESSAGES CONTROL], and check/add messages to disable:

disable=

Add this as an argument --rcfile="...standard.rc"

[2] Within VSC

https://stackoverflow.com/questions/7877522/how-do-i-disable-missing-docstring-warnings-at-a-file-level-in-pylint

In preferences, add:

"python.linting.pylintArgs": ["--errors-only"]


References

No comments: