[Python-Dev] PEP 366 - Relative imports from main modules

Nick Coghlan ncoghlan at gmail.com
Thu Jul 5 17:38:07 CEST 2007

Guido van Rossum wrote:
> Oh, one more thing. Perhaps we should rename it, like the other PEPs
> still active slated for inclusion in Py3k (and backporting to 2.6)?

Might as well be consistent - I'll take care of that when I update the 
PEP based on your suggestions.

> On 7/5/07, Guido van Rossum <guido at python.org> wrote:
>> I see no big problems with this, except I wonder if in the end it
>> wouldn't be better to *always* define __package_name__ instead of only
>> when it's in main? And then perhaps rename it to __package__? Done
>> properly it could always be used for relative imports, rather than
>> parsing __module__ to find the package. Then you won't even need the
>> error handler.

I'll have a look at what would be involved in always defining 
__package__ and using it for relative imports. I suspect it will be a 
slightly bigger change than the current PEP (i.e. more lines/files 
touched), but not significantly so.

>> FWIW, I find the PEP is rather wordy for such a simple proposal (it
>> took me more time to find the proposal than to understand it :-).

Yeah, I still haven't come up with a particularly concise way of 
explaining why relative imports don't currently work in main modules.

I'll rearrange the PEP to put the proposed fix before the detailed 
explanation of the problem (in fact, given that the latter is mainly of 
historical interest now, I may just include a pointer to the relevant 
section of PEP 338).


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list