[Python-projects] pylint version 0.16.0 doesn't complain about uninitialized variable
Aurélien Campéas
aurelien.campeas at logilab.fr
Thu Mar 5 11:00:13 CET 2009
Le Thursday 05 March 2009 10:55:38 Maarten ter Huurne, vous avez écrit :
> On Thursday 05 March 2009, Aurélien Campéas wrote:
> > Le Thursday 05 March 2009 10:07:23 Dotan Barak, vous avez écrit :
> > > Hi.
> > >
> > > I have the following function in my code:
> > >
> > > <--snip start-->
> > > import os
> > > import shutil
> > >
> > > def clear_temp_folder(temp_path):
> > > """ Remove old temporary folder if exists."""
> > >
> > > if os.path.exists(temp_path):
> > > try:
> > > shutil.rmtree(temp_path)
> > > rc = 0
> > > except OSError:
> > > rc = 1
> > > if rc:
> > > print "Error, failed to remove old temporary path %s" \
> > > % temp_path
> > > return rc
> > >
> > > return rc
> > > <--snip end-->
>
> (code adjusted to line wrapping)
>
> > > From doing code review by eye, i found out that the variable rc can be
> > > returned without any initialization,
> > > but the pylint could not find it.
> >
> > rc is either set in the try or in the except block
> > hence you don't risk a NameError
>
> This is true for the "if rc" line, but not for the "return rc" at the very
> end of the function.
>
oops, didn't catch this one :/
> Bye,
> Maarten
>
> _______________________________________________
> Python-Projects mailing list
> Python-Projects at lists.logilab.org
> http://lists.logilab.org/mailman/listinfo/python-projects
More information about the Python-Projects
mailing list