我在C#应用程序中托管IronPython并将主机的API注入全局范围.
我刚刚开始喜欢syntasticvim pylint来检查我的脚本.但是我[E0602, method_name] Undefined variable 'variable_name'对注入变量的所有错误消息感到恼火.
我知道使用# pylint: disable=E0602禁用此错误消息,但我不想仅为某些特定的变量名称削弱一个非常有用的功能.
你怎么处理这个?
目前,我在我的脚本顶部执行此操作:
try:
host_object = getattr(__builtins__, 'host_object')
except AttributeError:
pass # oops, run this script inside the host application!!
Run Code Online (Sandbox Code Playgroud)
我真正想做的是:
# pylint: declare=host_object, other_stuff
Run Code Online (Sandbox Code Playgroud)
在代码中禁用E0602:
# make pylint think that it knows about 'injected_var' variable
injected_var = injected_var # pylint:disable=invalid-name,used-before-assignment
Run Code Online (Sandbox Code Playgroud)
显然,每个模块需要进行一次,所有出现injected_var在此行之后对于pylint来说都是合法的.
| 归档时间: |
|
| 查看次数: |
18235 次 |
| 最近记录: |