I want SublimeLinter to ignore PEP-8 E402 error messages. I have changed the package user settings to
"pep8_ignore": [
"E402"
]
and have closed and reopened Sublime Text. SublimeLinter still displays an E402 error code. Why?
I am using ST3 with these packages: BufferScrool, LaTeXing, PackageControl, PackageResourceViewer, R-Box, Side Bar, Anaconda, and SublimeLinter.
So first, I'd note that Anaconda performs its own version of PEP-8 linting, so you've got some functional duplication happening...
Second, I'd note that you don't seem to have SublimeLinter-pep8 installed, which means (since SublimeLinter installed by Package Control on ST3 is going to be SublimeLinter3, which requires linting plugins to do anything) that its not SublimeLinter. Things to consider: (1) are the linting errors you see coming from Anaconda rather than SublimeLinter? If so you need to set "pep8_ignore" in the Anaconda user settings rather than SublimeLinter. (2) Are you (somehow) using the old, unsupported version of SublimeLinter on ST3? In that case, either (a) switch to using Anaconda and ignore SublimeLinter for the purposes of linting python files or (b) upgrade SublimeLinter to SublimeLinter3, install SublimeLinter-pep8 and see below.
Assuming you are actually trying to use the SublimeLinter-pep8 plugin on SublimeLinter3: SublimeLinter3, which uses an entirely different settings structure from the previous version of SublimeLinter. As a result, the "pep8_ignore" setting is no longer honoured. This is the expected behaviour.
In order to accomplish what you want you need these settings set in the settings file:
{
"user": {
"linters": {
"pep8": {
"ignore": "E402"
}
}
}
}
But have a careful read of the SublimeLinter settings docs as there are a lot of different ways to configure your settings, and have a look at the docs for the pep-8 plugin
As ig0774 mentioned, Anaconda has its own built-in linters (pylint, pep8, pep257, and pyflakes), which are producing the error message you'd like to ignore, not SublimeLinter. If for some reason you want to shut off linting with Anaconda and perform it with one or more SublimeLinter plugins, you'll need to install and configure those plugins. Search Package Control for more information.
To configure Anaconda, first open Preferences -> Package Settings -> Anaconda -> Settings-Default, then Settings-User in the same sub-menu. Copy the entire contents of Default to User, then close Default, as you can't edit it anyway. I highly recommend reading through the entire file, as it is well-commented. The setting you are looking for is also called "pep8_ignore", which in the current version of Anaconda is on line 318. This file seems to change rather often, so this position may change over time. Just search for the name.
If you want to turn off Anaconda's linting capabilities completely, set "anaconda_linting" to false.
Related
When running ipynbs in VS Code, I've started noticing Pylance warnings on standard library imports. I am using a conda virtual environment, and I believe the warning is related to that. An example using the glob library reads:
"env\Lib\glob.py" is overriding the stdlib "glob" modulePylance(reportShadowedImports)
So far my notebooks run as expected, but I am curious if this warning is indicative of poor layout or is just stating the obvious more of an "FYI you are not using the base install of python".
I have turned off linting and the problem stills persists. And almost nothing returns from my searches of the error "reportShadowedImports".
The reason you find nothing by searching is because this check has just been implemented recently (see Github). I ran into the same problem as you because code.py from Micropython/Circuitpython also overrides the module "code" in stdlib.
The solution is simple, though you then loose out on this specific check. Just add reportShadowedImports to your pyright config. For VS Code, that would be adding it to .vscode/settings.json:
{
"python.languageServer": "Pylance",
[...]
"python.analysis.diagnosticSeverityOverrides": {
"reportShadowedImports": "none"
},
[...]
}
I am using vscode with virtual environment (conda) to write python files on my mac.
I keep seeing import problems from pylance for specific third party AND official libraries (for example pyproj, geopy for third party, math for preinstalled).
for each file the errors/warnings look as follows:
I am sure that these packages are in my virtual environment (they are included in the conda list packages.
Although so far it seems to me as a cosmetic issue, removing these warnings would be very helpful.
Here (https://github.com/microsoft/pylance-release/blob/main/TROUBLESHOOTING.md#unresolved-import-warnings) there are some explanations but I did not fully udnerstand the issue or managed to resolve.
Add the following configuration in setting.json to remove these warnings
"python.analysis.diagnosticSeverityOverrides": {
"reportMissingImports": "none",
"reportUndefinedVariable": "none"
},
Use ctrl + shift +p to open the command palette. Search Settings, there are two settings.json files here. User works globally, Workspace works only on the current workspace. If the same configuration exists in both files, Workspace will override the settings in User.
I am currently able to use quick fix to auto import python functions from external typings such as from typing import List.
Python module quick fix import
However, I am unable to detect local functions/classes for import. For example: If I have the data class SampleDataClass in dataclasses.py, and I reference it in a function in test_file.py, VSCode is unable to detect it and I have to manually type out the import path for the dataclass.
Definition of dataclass
Reference to dataclass
I have the following extensions enabled:
Python
Pylance
Intellicode
My settings.json includes:
{
"python.envFile": "${workspaceFolder}/.env",
"python.languageServer": "Pylance",
"python.analysis.indexing": true,
"python.formatting.provider": "black",
"python.analysis.autoImportCompletions": true,
"python.analysis.autoSearchPaths": true,
"python.autoComplete.extraPaths": ["~/Development/<django repo name>/server"],
"python.analysis.extraPaths": ["~/Development/<django repo name>/server"],
"vsintellicode.features.python.deepLearning": "enabled",
}
I am using poetry for my virtual environment which is located at ~/Development/<django repo name>/.venv
Is there something that I'm missing?
Turns out the latest versions for Pylance broke quick-fix imports and any extra path settings for VSCode. When I rolled back the version to v2022.8.50 it now works again.
I filed an issue here: https://github.com/microsoft/pylance-release/issues/3353.
According to an issue I raised in github earlier, the developer gave a reply.
Custom code will not be added to the autocomplete list at this time (unless it has already been imported). This is done to prevent users from having too many custom modules, which may lead to too long loading time.
If necessary, you can start a discussion in github and vote for it.
Add:
I'm using vanilla Emacs and I installed lsp-mode as follows:
(use-package lsp-mode
:init
(setq lsp-keymap-prefix "C-c l")
:commands (lsp lsp-deferred)
:config (defun lsp-go-install-save-hooks ()
(add-hook 'before-save-hook #'lsp-format-buffer t t)
(add-hook 'before-save-hook #'lsp-organize-imports t t))
:hook (
(lsp-mode . lsp-enable-which-key-integration)
(go-mode . lsp-deferred)
(go-mode . lsp-go-install-save-hooks)
(typescript-mode . lsp-deferred)
(python-mode . lsp-deferred)
)
)
For Python I installed this. Everything seems to be working fine, but the problem is that I'm not able to override the default pycodestyle settings. For example, it complains about long lines > 79 so I tried adding in the root of the project the following setup.cfg:
[pycodestyle]
max-line-length=99
But it's not taken into account, am I missing something? I saw that there's the possibility to change the setting globally, but I'd like to have it on a per-project basis.
UPDATE
If pycodestyle is ran from the terminal it works as expected: it complains with the default line-length limit and it doesn't if I increase it to a value that is greater to the longest line that I have in the code.
The *lsp-log* buffer doesn't seem to provide any meaningful information:
Command "pyls" is not present on the path.
Command "pylsp" is present on the path.
Command "pyls" is not present on the path.
Command "pylsp" is present on the path.
Found the following clients for /<some path>/sample-app/sample_app/__init__.py: (server-id pylsp, priority -1)
The following clients were selected based on priority: (server-id pylsp, priority -1)
If I exec the flycheck-describe-checker command this is the output:
lsp is a Flycheck syntax checker.
This syntax checker checks syntax in the major mode(s)
`python-mode', `lsp-placeholder-mode', and uses a custom predicate.
Documentation:
A syntax checker using the Language Server Protocol (LSP)
provided by lsp-mode.
See https://github.com/emacs-lsp/lsp-mode.
If I disable flycheck by executing the command flycheck-disable-checker indeed the warnings go away, but it stops all the checks. So it seems like flycheck is the responsible for not honoring the setup.cfg.
I was able to understand what it seems to be happening. It seems that under the hood flycheck is using flake8 instead of pycodestyle. Indeed after I change setup.cfg into this:
[flake8]
max-line-length=99
Everything started working as expected.
The problem is that according to the documentation of python-lsp-server by default it should use pycodestyle. Moreover, checking through flake8 seems to be requiring 3rd party plugins according to the doc that I didn't install.
Not everything works as expected yet, as for example I have some complaints related to D100 and D104 that if I put them as ignore in the configuration their not honored yet.
I use VS Code Version 1.19.3 with Python 2.7 on Windows.
Recently pylint (code analyzer) shown an error message
"E1601:print statement used"
But I don't know why! Can someone help me?
The print statement is correct as per my knowledge!
Is it a bug or a feature is missing?
Greetings niesel
The warning originates from Pylint, which is a very helpful tool for a dynamic language with loose syntax like Python. Since you are programming in Python 2.x where print is perfectly valid, I suggest you put a file in the root of your repo named .pylintrc and use it to configure Pylint.
To disable the print warning and leave everything else to the default, enter these two lines in your .pylintrc file:
[MESSAGES CONTROL]
disable=print-statement
You will also need to tell Visual Studio Code to use your configuration file by opening your workspace or user settings and add this:
{
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": [
"--rcfile=/path/to/.pylintrc"
]
}
More options
To get a good idea of available configuration options open a terminal/prompt and run this command to generate a sample configuration file:
pylint --generate-rcfile > sample_pylintrc
The problem is, that changing from print statement to print function doesn't help much. So it seems, that it is some bug in VS Code Python module (2018.1 (01 Feb 2018)), as after this update I've found the same problem in my VS Code within my old projects
I've found reffered bug on their github
PS: vscode-python has changed pylint options since 2018.1. In order to return old behavior you may disable python.linting.pylintUseMinimalCheckers option for the workspace or for the userspace.
it's not an error per-se, it's just PyLint complaining about those legacy statements. PyLint will also complain about missing spaces before commas, those kind of style errors.
PyLint is there to warn you about possible problems. Your code will break when running python 3, so it warns you before it happens.
Note that print is a statement in python 2.x (which explains the message), and became a function in python 3.x.
Fix it by changing to:
print("test")
Since it's not a tuple, it works fine and does exactly the same for all versions of python, and PyLint will stop complaining.
you can also get rid of PyLint altogether: Windows 10 - Visual Studio Code - removing pylint (not sure if it's a good idea)