On Nov 30, 1:03 pm, Andrea Crotti <andrea.crott...@gmail.com> wrote: > Another thing about the AST, I am having fun trying to for example list > out all > the unused imports. > > I have already a visitor which works quite nicely I think, but now I > would like > to get a way to find all the unused imports, so I need more visitors that > find out all the used names. > > I didn't find too much documentation about these kind of things, so any > suggestions on how to approach? > > Pylint and snakefood have similar code, but they use the old "compiler" > module, > so it's not really helpful.
There was another topic in these forums recently about "un-importing" modules (and how you can not do that reliably without restarting python). There was various ways mentioned of keeping track of what was imported. And there was mentioned reasonable ways of finding all possible imports on a computer. By "unused imports" I assume you mean "all unused imports in the application's source code" as opposed to meaning "all unused modules/ packages/libraries on that computer." Personally I'd love to see more tutorials on the AST module; An AST for Dummies. Pretty much the tutorials talk about parsing an expression like "1+2=3". But I'd like to see how blocks are compiled/ managed by the indent/dedent tokens and how the complete algorithm for finding qouted strings is implimented (using really simple explanations). Some google buzzwords to help with your search for your question: sys import cache, import hook, pydoc walkpackages(). And I just found this little tool; never knew about it: C:\PythonXX \Tools\Scripts\pydocui.pyw -- http://mail.python.org/mailman/listinfo/python-list