5

I have recently installed Python Language Server in Visual Studio Code.

I sometimes have some warnings that I want to locally disabled

For example, let's assume I have the following code:

import org.sikuli.script.SikulixForJython
from sikuli.Sikuli import *
from guide import *

It is normally run from Sikulix, which uses Jython libraries. Since my favorite editor cannot load this module, it would raise a warning:
unresolved import 'org.sikuli.script.SikulixForJython' Python(unresolved-import)

With pylint, I can disable that warning for only these 3 lines with something like:

# pylint: disable=unresolved-import
import org.sikuli.script.SikulixForJython
from sikuli.Sikuli import *
from guide import *
# pylint: enable=unresolved-import

How to do something similar with Python Language Server?

Thanks

Jean-Francois T.
  • 11,549
  • 7
  • 68
  • 107
  • 1
    An alternative is to disable warning globally via the settings `"python.analysis.disabled": ["too-many-function-arguments", "parameter-missing"],` but I am looking for a local solution (i.e. class, function, conditional block) – Jean-Francois T. Mar 25 '19 at 10:39

3 Answers3

4

There's currently no support for per-line warning suppression. To request such a feature, please open an issue at https://github.com/microsoft/python-language-server.

Brett Cannon
  • 14,438
  • 3
  • 45
  • 40
  • 3
    I had already requested the feature. Such query was related to an issue that already existed: https://github.com/Microsoft/python-language-server/issues/264 – Jean-Francois T. Mar 26 '19 at 02:08
2

There are two types of settings in vscode:

  • Global: settings.json. This can be reached using ctrl + , and on the top right panel, clicking on the brackets icon (Open settings (JSON)).

  • Local: ${workspaceFolder}/.vscode/settings.json

So what you should do is just creating file ${workspaceFolder}/.vscode/settings.json and adding line "python.analysis.disabled": ["too-many-function-arguments", "parameter-missing"], to it.

amirali
  • 1,888
  • 1
  • 11
  • 32
  • A short tip: There's no need to create the file yourself. After opening `Settings`, first click on the link `Workspace Settings` (at the top). If you now click on the curly brackets in the upper right, VSCode will automatically create (or open an existing) `settings.json` for the current workspace ;-) – Joey Mar 25 '19 at 11:05
  • 1
    That is a first step to do what I want. However, I would like to keep the warning for the other `import` (so basically disabling the warning just for 3 lines). I have updated the question to make it clearer. – Jean-Francois T. Mar 25 '19 at 13:20
0

There is now a partial implementation of linting disabling (for all warnings/errors of a single line).

You can use the keyword # noqa to disable the warning, as tracked in this issue: https://github.com/Microsoft/python-language-server/issues/264

The code updated to disable warnings from Pylan would then be:

import org.sikuli.script.SikulixForJython  # noqa
from sikuli.Sikuli import *  # noqa
from guide import *  # noqa
Jean-Francois T.
  • 11,549
  • 7
  • 68
  • 107