Proposal: Inline Import

Shane Hathaway shane at hathawaymix.org
Fri Dec 9 15:56:08 EST 2005


Benji York wrote:
> Why not: 1) jump to the top of the file when you need to do an import 
> (1G in Vim), 2) add the import, 3) jump back to where you were (Ctrl-o 
> in Vim) and keep coding.  This isn't Vim specific, I suspect all decent 
> editors have similar capabilities (I know Emacs does).  Thus eliminating 
> the unpleasant scan step.

That's something the computer should do for me.  It's busywork.  Eclipse 
practically eliminates this busywork when I'm writing Java code: if I 
autocomplete a name, it also quietly adds the corresponding import 
statement.  It also generates import statements when I copy/paste code. 
  The structure of the Java language makes this relatively easy.

In Python, it's harder to do autocompletion with the level of accuracy 
required for import statement generation.  However, inline imports could 
eliminate the need to generate import statements.

> Oh, and py.std does something similar to what you want: 
> http://codespeak.net/py/current/doc/misc.html#the-py-std-hook.

Either form of inline import (py.std or my proposal) is a major 
idiomatic change.  I can't be too much of a cowboy and start using 
idioms that are completely different from standard Python usage; my code 
would become unmaintainable.  Thus a prerequisite for using inline 
import is broad approval.

Shane



More information about the Python-list mailing list