Sunday, June 15, 2008

Organizing imports

One of the features I can't live without in Pydev Extensions is the auto-import. Basically, when you want to get a class/method into the namespace, just start writing it, request a completion and the class will be completed and an import for it will be added at the top-level part of the file (it's similar to what JDT does).

So, after using this feature lots of times, one thing that started happening is that some modules would end with imports such as:

from mod1 import Class1from mod1 import Class2from mod1 import Class3

Now, on version 1.3.18, the auto-import will group imports when requested, so, after making those requests it'd become:

from mod1 import Class1, Class2, Class3

But that won't group existing imports... For that, the organize imports action was improved -- until now, Ctrl+Shift+O would only sort the imports alphabetically, but from now on it'll also group them, and if Pydev Extensions is available, for each undefined token found in the code analysis, an option to add an import to one of the available definitions of the token will be presented -- which is especially useful when doing refactorings and cutting/copying code from one place to another.

Actually, currently there are no plans of separating imports into different sections... you can enter a feature request if you'd like to have it -- or send a patch, as that part is in the open-source version ;-)