On Thu, Mar 15, 2018 at 5:25 AM, Brendan Barnwell <brenb...@brenbarn.net> wrote: > On 2018-03-14 04:18, Steven D'Aprano wrote: >> >> Apart from intentionally manipulating sys.modules or the import system, >> or playing file system tricks like hard-linking your files, under what >> circumstances can this occur by accident? > > > It can occur if a given directory winds up appearing twice on the > import path. For instance, if /foo is on the path and /foo/bar is a package > directory with /foo/bar/baz as a subpackage directory, then you can do "from > bar import baz" and "import baz" and wind up with two different module > objects referring to the same module. > > This usually happens when code starts adding paths to sys.path. > This is in some sense "manipulating the import system" but it's something > that a fair number of libraries do in various contexts, in order to be able > to do things like import plugins without requiring the user to make those > plugins available on the default import path.
Or by running something that's part of a package, thus making the current directory automatically available. spam/ __init__.py spam.py ham.py python3 spam/spam.py If it now says "from spam import ham", is it going to get ham.py, or is it going to try to pull up ham from spam.py? ChrisA _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/