Why does Pylint give error E0702, raising NoneType, on this raise statement?
Say I have the following code.
def foo():
foobar = None
if foobar is not None:
开发者_Go百科 raise foobar
When I run this code through pylint, I get the following error:
E0702:4:foo: Raising NoneType while only classes, instances or string are allowed
Is this a bug in pylint? Is my pylint too old?
pylint 0.18.0,
astng 0.19.1, common 0.45.0
Python 2.5.1 (r251:54863, Aug 25 2008, 09:23:26)
Note: I know this code doesn't make any sense, it's distilled to its bare bones to expose the issue at hand, normally stuff happens in between line 2 and 3 which could make foobar not be None, and no I can't just raise an exception there, because that happens in another thread that has restrictions on it.
It's a known bug. Pylint doesn't do a lot of flow-control inferencing.
Luckily you can tell pylint that you know better than it does:
def foo():
foobar = None
if foobar is not None:
raise foobar # pylint: disable-msg=E0702
精彩评论