[New-bugs-announce] [issue22285] The Modules/ directory should not be added to sys.path

STINNER Victor report at bugs.python.org
Wed Aug 27 12:07:47 CEST 2014


New submission from STINNER Victor:

When Python is built from source, the "Modules/" subdirectory is added to sys.path on UNIX. I don't understand why: it does not contain .py files nor .so dynamic modules. Dynamic modules are built in "build/lib.linux-x86_64-3.5-pydebug".

A side effect of adding Modules/ subdirectory to sys.path is that Modules subdirectories (ex: _sqlite, _ctypes, _io, _decimal, etc.) can be used as packages.

For example, when the _decimal module cannot be compiled, Lib/decimal.py uses Modules/_decimal as a Python package which is wrong. The decimal becomes an empty module (no symbol, because Modules/_decimal does not contain an __init__.py nor any .so file) because decimal.py uses "import _decimal" at the end (see decimal.py).

Attached patch removes Modules/ from sys.path on UNIX.

Maybe adding Modules/ to sys.path was useful before the introduction of pybuildir.txt? See issue #9589 and the changeset 4742e7aea2f5 (and the issue #586680).

----------
files: getpath_no_modules.patch
keywords: patch
messages: 225955
nosy: haypo, pitrou
priority: normal
severity: normal
status: open
title: The Modules/ directory should not be added to sys.path
Added file: http://bugs.python.org/file36484/getpath_no_modules.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22285>
_______________________________________


More information about the New-bugs-announce mailing list