views:

49

answers:

2

Say I have the following code.

def foo():
    foobar = None
    if foobar is not None:
        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.

+5  A: 

It's a known bug. Pylint doesn't do a lot of flow-control inferencing.

John Feminella
Thanks, was afraid of that.
wich
heh, you know what's funny... I know the reporter ;)
wich
Small world! :)
John Feminella
+2  A: 

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
Ned Batchelder
Yes, that I know.
wich