[Python-projects] Spurious warning about possibly unused loop var
Sylvain Thénault
sylvain.thenault at logilab.fr
Mon Nov 24 08:02:26 CET 2008
On Sat, Nov 22, 2008 at 09:02:07PM -0600, skip at pobox.com wrote:
>
> Clipped almost byte-for-byte from the SpamBayes source code:
>
> def f(self, v0, v1):
> for sep in [' ', ',', ':', ';', '/', '\\', None]:
> # we know at this point that len(self.value) is at
> # least two, because len==0 and len==1 were dealt
> # with as special cases
> test_str = str(v0) + sep + str(v1)
> test_tuple = self.split_values(test_str)
> if test_tuple[0] == str(v0) and \
> test_tuple[1] == str(v1) and \
> len(test_tuple) == 2:
> break
> # cache this so we don't always need to do the above
> self.delimiter = sep
>
> Pylint (0.15.2, astng 0.17.4, common 0.36.1) complains about the assignment
> after the for loop:
>
> loopvar.py:13: [W, f] Using possibly undefined loop variable 'sep'
>
> Given that the list is a non-empty list of literals I think it's safe to
> assume that sep will have a value when the loop completes.
the same kind of problem is reported in ticket http://www.logilab.org/ticket/2463
--
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