On 18 March 2017 at 00:00, Paul Moore <p.f.mo...@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 | ncogh...@gmail.com | Brisbane, Australia
_______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org https://mail.python.org/mailman/listinfo/distutils-sig