On Tue, Jun 05, 2007 at 12:59:32PM +0200, Adam Groszer wrote: > Tuesday, June 5, 2007, 12:50:40 PM, Hermann wrote: > > During development and especially refactoring, I'm often confronted with > > cleaning up import statements. > > > Missing imports are reported by Python, however, unneeded imports are not. I > > don't know if unneded imports are a performance issue, nevertheless it > > probably makes sense to clean them up from time to time. > > > Therefore I wonder if there's some tool that can automatically check if an > > import is needed or not. Probably this is easy to write, but perhaps > > somebody > > has already done so? > > > What would be nice, would also be a tool that crawls through a python > > package > > and also checks any missing imports and reports all of them at once. When I > > refactor code, I often have to restart zope3 over and over, only due to > > missing import statements.
I have a quick-and-dirty python script that does exactly this. It cannot handle the "new" Zope import style which is import somepackage.somesubpackage from somepackage import otherpackage import somepackage.otherpackage.othersubpackage x = somepackage.somepackage.somevar y = otherpackage.othersubpackage.othervar and which I don't personally use. (If I wanted verbosity, I know where to find Java). (And while I'm on the topic of strong opinions: A: No. Q: Should I include quotations after my reply? ) > Z3 has an importchecker: > > """Import checker > > This utility finds unused imports in Python modules. Its output is > grep-like and thus emacs-friendly. > ... I ought to try this one out some day... > Althought pyflakes works for me better. > http://www.divmod.org/projects/pyflakes pyflakes doesn't handle imports that are used by doctests only, e.g.: import doctest import something def doctest_foo(): """ >>> use something """ def doctest_bar(): """ >>> use something """ def test_suite(): return doctest.DocTestSuite() Can the import checker in Z3 handle this? Marius Gedminas -- To stay awake all night adds a day to your life. -- Stilgar (Frank Herbert _Children_of_Dune_)
Description: Digital signature
_______________________________________________ Zope3-users mailing list Zope3email@example.com http://mail.zope.org/mailman/listinfo/zope3-users