Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
703 views
in Technique[技术] by (71.8m points)

python - How to disable pylint 'Undefined variable' error for a specific variable in a file?

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...