[issue29723] 3.6.1rc1 adds the current directory to sys.path when running a subdirectory's __main__.py; previous versions did not
Eryk Sun
report at bugs.python.org
Wed Mar 8 14:53:54 EST 2017
Eryk Sun added the comment:
main361 can be run as a package from the current directory via -m because an empty string is in sys.path, i.e. the current directory. It imports the package, executing __init__.py and then __main__.py. In this case, the main361 directory/zip import source is not added to sys.path.
When we run main361 as a script, the main361 package is not imported, i.e. __init__.py is not executed. The siblings of the __main__.py script are in the main361 directory (or zip file). Effectively this is the script directory, and it does belong in sys.path -- even in isolated mode because we trust the directory or zip file that contains __main__.py.
A potential problem, however, is that we don't ensure the __main__ import source is added as an absolute path. So if the script changes the working directory, then it loses this import source and possibly (unlikely) gains a new import source if the relative path exists relative to the new working directory.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29723>
_______________________________________
More information about the Python-bugs-list
mailing list