[Pythonmac-SIG] Determining if I need an import

Chris Weisiger cweisiger at msg.ucsf.edu
Mon Jan 24 23:52:43 CET 2011


I've inherited a large codebase that is practically the definition of
"legacy", with all that entails. I've spent a lot of time removing unused
code, renaming variables, creating classes, moving global variables to
locals (let's stuff all our program state into a single module and then just
import that whenever we want to access it!), and so on, and now I want to
start cleaning up the dependency chains between different modules.

There's several places where I've had to move an import statement from being
at the top of the module to being inside a function right before it's used,
to prevent circular dependencies from causing imports to fail at program
start. I wouldn't be surprised if I've rendered many of these imports moot,
but short of a fair amount of painful grepping across ~20k lines of Python,
I don't know of an easy way to find them.

Is there a tool that examines your actual and apparent dependencies? I know
there are programs that will generate dependency graphs, but for those
there's little difference between a tight coupling and a single import
statement that isn't actually needed.

(Though if you'd care to recommend a dependency graph generator, I'd like to
hear about that too)

-Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20110124/5d49a631/attachment-0001.html>


More information about the Pythonmac-SIG mailing list