I have following vimrc, but I do not get arrows for warnings and error from syntastic
like on the picture below
Further more I am not able to use the ruler with set ruler. Why I do not get a warning that variable "a" is not used?
What did I do wrong?
Thank you in advance.
Syntastic is checking your code for compliance with PEP8.. This is a recommendation usually followed by the Python community around formatting your code.
The first error is because you did import os but then you don't actually call any methods from os in your code since that line is commented out. You shouldn't import modules you don't use.
The second is because PEP8 specifies that you should have 2 blank lines between the imports and the start of your code.
The third is because PEP8 also says there should be no trailing whitespace.
As far as the ruler goes, I'm not exactly sure as to what you're referring.
Related
Please help, it's driving me nuts. I tried following another older stack overflow post and it didn't work. I just declare a new variable and I already get squiggly line - what an annoying feature. Using python by the way on VSC.
Something like this:
My json.settings look like this:
Based on the information you provided, I reproduced the problem.
The reason is that Python's code analysis tool Pylint detects that the variable "words_to_remove" is not used, so it displays "Pylint(Unused variable)".
Solution:
Complete the code. for example:
Turn off the prompt of Pylint.
1). Close the "Unused variable" prompt of pylint:
Please use "python.linting.pylintArgs": ["--disable=W0612"], in settings.json:
2). Close Pylint.
Use "python.linting.enabled":false , in settings.json.
In addition, Pylint is an excellent Python code analysis tool. It will provide good suggestions on the format and syntax of the code we edit and it does not affect the execution of the code.
Therefore, if you want to turn off Pylint related prompts to remove the wavy lines, it is better to set it off after the code can be executed.
I need to have this line in the beginning of a python file:
#script_exec_time: 500
There should not be any space between the # and script_exec_time. This is because the python file is parsed by another script and it will not consider the script_exec_time if there is a space.
I cannot modify the script that parses my python file because I do not have access to it.
Now when I lint using pylint, it automatically gives a space between the # and script_exec_time.
I tried using other linters like flake8, but even they do the same thing.
I still want to use the linter because it makes it much easier to code.
Is there any way to modify pylint settings so that it ignores comments from it's automatic formatting? Or is there any workaround I could use here?
Edit: I tried the same thing by disabling the linter. The problem persisted. It was not related to linter I think. Anyway I found a workaround and I am posting that as an answer.
As Vaibhav Vishal pointed out in his comment, linters like Pylint and flake8 do not reformat code, they just flag code that triggers a lint rule.
You most likely have a formatter installed and configured. See the formatting docs on how this is done and basically do the reverse. :)
All I did was to wrap the original comment in side a block comment, like so:
#script_exec_time:5000
'''
#scrript_exec_time:5000
'''
Vscode will not format anything that is there inside the block comments.
I have a lot of datamodels in a datamodel/ directory and I don't want to import them one by one so I did:
from datamodel import * # pylint:disable=unused-wildcard-import
and then further on I did:
datamodel_file.DataModelClass(db_server)
I get the following errors in VS Code:
Undefined variable 'datamodel_file' (pylint(undefined-variable)[22,27]
Undefined variable: 'datamodel_file' (Python(undefined-variable)[22,27]
A few problems with this:
I don't understand why VS Code/PyLint thinks that this variable is undefined as the code runs fine when I debug it
Why are there 2 error messages?
I tried to disable the pylint message as a quick try-and-see-what-happens by doing:
datamodel_file.DataModelClass(db_server) # pylint:disable=undefined-variable
This has the effect of disabling the error from pylint but that other error from Python still remains.
How should I fix this error?
Using import * is discouraged outside of the REPL because of situations like this where you can't tell from introspecting the code where the name is supposed to come from. Chances are datamodel specifies datamodel_file in some funky way that Pylint or the language server can't figure out.
As for the two linter warnings, that's because you're running two tools at once: Pylint and the Python language server which provides basic linting. If you want to disable the Python language server one please see the docs on its settings.
But the best way to solve this is simply to not use import *. Either do import datamodel and then use datamodel.datamodel_file (or do something like import datamodel as dm; dm.datamodel_file). Or you can use from datamodel import datamodel_file.
I've just started looking at the Vim jedi plugin, and it seems pretty impressive. One feature of some of the Java IDEs I've used is the ability to automatically add required imports. Can Jedi do that? For example, if I enter a line such as
arg1 = sys.argv[1]
and then invoke some Jedi command, is it possible for the plugin to automatically insert an import sys line at the top of the source file (if sys is not already being imported)?
I've looked through the Jedi help, and can't see anything like this - but it's possible I missed something. Alternatively, is there another Vim plugin that would do this? (It needs a certain level of understanding of Python syntax to get it right, which is why I looked to Jedi to be able to do it).
Currently Jedi doesn't do refactoringing. This includes import additions. There's an issue for the whole subject: https://github.com/davidhalter/jedi/issues/667.
It's not that easy to implement this command with good performance. However any help is appreciated. :)
FIY, I've defined a generic import feature that can be used on demand in lh-dev. I use it from my C&C++ suite, and from my snippet engine (mu-template).
So far I don't parse anything to add the missing import/include statements. This part would be complex as Dave said. Instead my snippets know which files need to be imported/included and import/include them if not already imported/included.
It's far from being perfect, but it's a start. mu-template provides a hook to do stuff at the start of the file after the snippet has been expanded, this is where I call lh-dev function. If other snippet engines provide similar hooks, you should be able to call lh#dev#import#add() from your snippets.
Here a proof of concept snippet for Python (I seldom program in Python, and don't have many snippets for it): https://github.com/LucHermitte/mu-template/blob/master/after/template/python/path-exists.template
I am developing using PyDev in Eclipse. I have put in some comments in my code. I get wavy red lines underneath certain words. The program runs fine and there are no warnings mentioned. So what is the meaning of these wavy lines.
e.g.
#!/usr/bin/python - I get the line under usr and python
# generated by accessing registry using another script written in VBScript.
# The scripts can do the follwing things.
- I get wavy lines under the words registry and following.
I need these comments as I may run the module on its own later.
Thanks for the help.
Neil speaks the truth, except for telling you to turn it off -- spell check in comments is quite helpful -- those who come after will thank you for ensuring they can read your comments without trying to decode random spelling errors.
The lines are simply pointing out words your IDE thinks are spelled wrong. I don't know why it doesn't understand "registry", but you have, in fact, misspelled "following" (as "follwing"). Fix the latter, ignore the former (or add it to the dictionary, don't remember if there's a convenient mechanism for that There is! See Macke's helpful comment below.).
Might be this is just a spellchecker. You have a typo "follwing" instead of "following".