Proposal: Inline Import

Shane Hathaway shane at hathawaymix.org
Fri Dec 9 19:31:18 EST 2005


Xavier Morel wrote:
> Shane Hathaway wrote:
> 
>>Thoughts?
> 
> 
>  >>> import re; name_expr = re.compile('[a-zA-Z]+')
>  >>> name_expr
> <_sre.SRE_Pattern object at 0x00F9D338>
>  >>>
> 
> the import statement can be called anywhere in the code, why would you 
> add strange syntactic sugar that doesn't actually bring anything?

That syntax is verbose and avoided by most coders because of the speed 
penalty.  It doesn't replace the idiom of importing everything at the 
top of the module.

What's really got me down is the level of effort required to move code 
between modules.  After I cut 100 lines from a 500 line module and paste 
them to a different 500 line module, I have to examine every import in 
both modules as well as examine the code I moved for missing imports. 
And I still miss a lot of cases.  My test suite catches a lot of the 
mistakes, but it can't catch everything.

If I could just avoid import statements altogether, moving code would be 
easier, regardless of extra typing.  But I can't avoid import statements 
unless there's a different way to import that lots of people like.

Shane



More information about the Python-list mailing list