[PATCH 0 of 6] Fix problems found by Pyflakes

Joel Rosdahl joel at rosdahl.net
Tue Mar 4 07:25:12 UTC 2008


I noticed an unbound name in a Mercurial source file and decided to
try running Pyflakes on the code to see if I could find other similar
problems. This patch series is the result of my experiment.

Pyflakes is quite simplistic (but fast) and is not able to analyze
files that import names using an asterisk (i.e., "from foo import *").
With some exceptions, the first patch is just an expansion of all such
imports. One exception is mercurial/util.py, which has "from
util_win32 import *" -- I guess there would be objections to expanding
that one.

A possibly controversial thing about the first patch is that it
removes the import of everything in mercurial.node/mercurial.repo from
mercurial/hg.py, which means that mercurial.node/mercurial.repo stuff
won't be importable from mercurial.hg anymore. The patch of course
compensates for this in all code in the repository, but maybe there's
external code that will break? (And if so, does it matter? I don't
know.)

In addition to enabling Pyflakes checking, I also think it's good
style to avoid "star imports".

The second patch removes a bunch of unused imports noted by Pyflakes.

After applying the first two patches, the output of Pyflakes gets
quite easy to overview. There are a some bogus "redefinition of unused
'name'" messages, some messages from imports that are only done to
catch import errors, etc, but some real errors are found.

Patches three to six are corrections of "unbound name" errors found by
Pyflakes. If you don't like the two first patches, it should be
possible to just apply the rest (with some minor modifications).

Regards,
Joel


More information about the Mercurial-devel mailing list