[Distutils] [proposal] version-free + lookup-friendly dist-info location

Nick Coghlan ncoghlan at gmail.com
Fri Mar 17 10:40:33 EDT 2017


On 18 March 2017 at 00:00, Paul Moore <p.f.moore at gmail.com> wrote:

> As a theoretical example:
>
> foo 1.0 looks like this:
>
>     foo
>         __init__.py
>         bar.py
>
> foo 2.0 moves the functionality of foo/bar.py into baz.py
>
>     foo
>         __init__.py
>         baz.py
>
> Put both of these on sys.path, then you can successfully import
> foo.bar and foo.baz. Which is of course wrong. Furthermore, which
> version of foo/__init__.py gets imported depends on which version of
> foo is first on sys.path, so one of bar and baz will be using the
> wrong foo.
>

Unless the __init__.py has its own __path__ extension code, whichever
version of "foo" is first on sys.path will "win", and you won't be able to
import from the other one (so you'll be able to import "foo.bar" or
"foo.baz", but not both). That's not an accident, it's behaviour that was
deliberately kept for backwards compatibility reasons when PEP 420's native
namespace package support was being designed.

You only get the "you can import both of them" behaviour if "foo" is a
namespace package, at which point "foo" itself doesn't really have a
version any more.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20170318/9653819e/attachment.html>


More information about the Distutils-SIG mailing list