问题描述
说我有以下代码。
def foo():
foobar = None
if foobar is not None:
raise foobar
当我通过pylint运行此代码时,我收到以下错误:
E0702:4:foo: Raising NoneType while only classes, instances or string are allowed
这是pylint中的错误吗? 我的幽灵太老了吗?
pylint 0.18.0,
astng 0.19.1, common 0.45.0
Python 2.5.1 (r251:54863, Aug 25 2008, 09:23:26)
注意:我知道这段代码没有任何意义,它已被提炼到其裸露的骨头以暴露手头的问题,通常情况发生在第2行和第3行之间,这可能使foobar不是None,而且我不能只是在那里引发异常,因为这发生在另一个对它有限制的线程中。
1楼
这是 。 Pylint没有做很多流量控制推理。
2楼
幸运的是,你可以告诉pylint你知道的比它更好:
def foo():
foobar = None
if foobar is not None:
raise foobar # pylint: disable-msg=E0702