[Python-bugs-list] [Bug #115528] import creates extra modules if in working directory

noreply@sourceforge.net noreply@sourceforge.net
Thu, 28 Sep 2000 06:15:18 -0700


Bug #115528, was updated on 2000-Sep-27 20:08
Here is a current snapshot of the bug.

Project: Python
Category: Core
Status: Closed
Resolution: Invalid
Bug Group: Not a Bug
Priority: 5
Summary: import creates extra modules if in working directory

Details: Given the directory structure:

lib/
    foo/
         __init__.py
         bar.py

and PYTHONPATH includes lib

If my current working directory is lib/foo, then
>>> import bar
>>> print bar.__file__
bar.py
>>> import foo.bar
>>> print foo.bar.__file__
lib/foo/bar.py
>>> print bar == foo.bar
0

I think that any one file should produce only one module at runtime and this behavior is wrong.

The reason I am trying to count on file-module mapping is because I was to index some behavior by class, and if I can't count on classes from the same file testing identical then I'm stuck.

Follow-Ups:

Date: 2000-Sep-28 06:15
By: fdrake

Comment:
This is a result of including both lib/ and . (as '') on sys.path; the file is legitimately found for two different module imports, so it is loaded for each.  We recommend that you do not run the Python interpreter from within a package; determining this situation from the interpreter at runtime would be prohibitively expensive and slow startup.
-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=115528&group_id=5470