[Python-Dev] PEP 328 - Relative Imports

Guido van Rossum gvanrossum at gmail.com
Wed Sep 8 17:11:28 CEST 2004


> I know that this has been discussed a few times in the past,
> but the more I have to deal with building applications using
> third-party libs or packages, the more I get the feeling that
> the choice of making "import module" absolute is the wrong
> path to follow.
> 
> The typical scenario goes like this:
> 
> * you build an application that uses various third-party
>    packages and has to maintain them inside another package,
>    e.g. ThirdPartyCode
> 
> * you don't have access to the (third-party) package source code or
>    it's not feasable to make changes to it for maintenance reasons
> 
> Another common case is that you have to deal with third-party
> code that is not properly packaged as Python package, but comes
> as a set of top-level modules.
> 
> In this scenario you typically put all those files into a
> newly created Python package directory and access the modules
> in that directory using the package name.
> 
> In Python 2.3 and 2.4 (as well as all previous versions), both
> scenarios can easily be implemented without having to change
> the third-party code.
> 
> The PEP however suggests that starting with 2.5, the interpreter
> will issue a warning and 2.6 should default to absolute paths.
> 
> I'd like to request that the latter change be postponed to
> Python 3k, or that some other way of supporting the above
> scenarios is provided that can be enabled in the application.
> 
> Please remember that changes to application code are well
> possible. What's not possible is making changes to the
> packaged third-party code.

As long as it's clear that this is a compatibility requirement only I
think it's a good idea to support this way of developing apps (even
though I think that clever sys.path manipulation can probably get
around it, it's not worth breaking existing approaches). All new apps
should however use relative imports to reference their own code, so
the problem won't be repeated in the future.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
Ask me about gmail.


More information about the Python-Dev mailing list