Proposal: Inline Import

Steve Holden steve at holdenweb.com
Sat Dec 10 03:53:09 EST 2005


Shane Hathaway wrote:
> 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/past
e code.
>   The structure of the Java language makes this relatively easy.
> 
And there's so much more busywork in Java that it's probably worth 
automating. See

   http://www.artima.com/weblogs/viewpost.jsp?thread=42242

> 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

Good luck.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list