Installing namespaced wheels creates .pth
files that inject invalid modules into sys.modules.
#12965
Closed
1 task done
Labels
Description
Installing a wheel with a
namespace_packages.txt
trigger file (e.g.sphinxcontrib_jsmath-1.0.1-py2.py3-none-any.whl
) will generate an executable.pth
file (e.g..../site-packages/sphinxcontrib_jsmath-1.0.1-py3.7-nspkg.pth
) that dynamically creates a namespace module and injects it intosys.modules
. This module has an invalid__file__
property. If defined, this property must be a string. but it isNone
in this case, breaking other tools that depend on this property to be a string, if present.Expected behavior
The
__file__
attribute of all loaded modules should be either a string, or missing completely, but neverNone
.pip version
24.0
Python version
3.12
OS
Linux
How to Reproduce
pip install sphinxcontrib-jsmath
python3 -c 'import sys; mfile = getattr(sys.modules.get("sphinxcontrib"), "__file__", "UNSET"); print(f"sphinxcontrib.__file__ = {mfile!r}")'
Output
This prints
sphinxcontrib.__file__ = None
. Note thatsphinxcontrib
does not need to be imported, it is injected during runtime initialization by a.pth
file.Code of Conduct
The text was updated successfully, but these errors were encountered: