I am hosting IronPython inside a C# application and injecting an API for the host into the global scope.
I have just started to love syntastic
for vim with pylint
for checking my scripts. But I am getting annoyed by all the [E0602, method_name] Undefined variable 'variable_name'
error messages for the injected variables.
I am aware of using # pylint: disable=E0602
to disable this error message, but I'd prefer not to cripple a really useful feature just for some specific variable names.
How do you deal with this?
Currently, I am doing this at the top of my script:
try:
host_object = getattr(__builtins__, 'host_object')
except AttributeError:
pass # oops, run this script inside the host application!!
What I would really like to do is this:
# pylint: declare=host_object, other_stuff
Actually, there is a way to disable pylint argues about the specific undefined variable(s) by specifying it in dummy-variables-rgx (or dummy-variables in the older
pylint
versions).dummy-variables
contain_,dummy
by default and overwritten with the user-specified values onpylint
execution:or for the older
pylint
versions:Or in case of the
pylint
configuration for VSCode (User/Workspace Settings
can be opened by pressing Ctrl + ,):Disabling E0602 in the code:
Obviously, that needs to be done once per module, all occurrences of
injected_var
after this line would be legal for pylint.Not for variables, but you can disable it for the lines that have the var. See the ref.
I just faced this issue and I just added disable options in pylintrc file. In my case, I am working on a small script and some of pylint checks are a bit overkill. So I disabled Undefined Variable Error
by
disable=E0602, E0603
You can find the codes and meaning at: http://pylint-messages.wikidot.com/all-codes
My pylintrc file:
You can add your variables to the 'additional-builtins' option so pylint will consider them as defined.
This has to be done in a rc file, it can't be done inlined in the code.
There's
good-names=host_object,other_stuff
oradditional-builtins=...
for this, or for some advanced stuff you can modify the regex viavariable-rgx
.