[Python-projects] Pylint false positive W0706 : identifier used
to raise an exception is assigned ...
Sylvain Thénault
sylvain.thenault at logilab.fr
Mon Aug 21 16:27:25 CEST 2006
On Monday 21 August à 10:10, Pierre_Rouleau at ImpathNetworks.com wrote:
> Bonjour,
>
> When parsing the following code, Pylint issues warning W0706 event though the
> code checks to prevent raising an exception when the identifier is bound to None
> or 0.
> It would be nice that Pylint refrain from issuing the warning when the code has
> a check to prevent the error from occuring.
hum, that's really not easy right now without much better flow control. And even with the test,
it looks like smelly code to me... I think this case is rare enough to disable the message
locally when needed.
> Another note: the error message identifies the line of the assignment when the
> identifier is assigned 0 but not when it is assigned None.
> Why not give the line number for the assignment to None?
line number bugs are usually related to the std lib's compiler module. I'll have a look at it
anyway.
>
> Code:
> #---------------
> def test_raise(fname):
> """Test if pylint handles raise of None properly."""
>
> error = None
> try:
> fd = open(fname, 'w')
> except IOError, exp:
> error = exp
> fd = None
> if fd:
> fd.close()
> if error:
> raise error # this issues W0706:
> # Identifier used to raise an exception is assigned to
> None
I guess you know this stripped test case would be better written as :
def test_raise(fname):
"""Test if pylint handles raise of None properly."""
try:
fd = open(fname, 'w')
fd.close()
except IOError, exp:
raise
or even
def test_raise(fname):
"""Test if pylint handles raise of None properly."""
fd = open(fname, 'w')
fd.close()
:) Of course that's probably not that easy on your actual case...
regards,
--
Sylvain Thénault LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian: http://www.logilab.fr/formations
Développement logiciel sur mesure: http://www.logilab.fr/services
Python et calcul scientifique: http://www.logilab.fr/science
More information about the Python-Projects
mailing list