Nick Coghlan <ncogh...@gmail.com> added the comment:
Serhiy's analysis sounds right to me - for precompiled bytecode files, we really want co_filename to reflect the import time filename *not* the compile time filename. While zipimport is one way to get the compile time and import time paths to differ, there are others: - move an existing directory to another location - copy a directory tree to a different machine - move an implicitly cached pyc file to another location Concrete example from a recent'ish build where I convert an implicitly cached pyc to a standalone one, but co_filename still references the original source file: =========== $ ./python -c "import contextlib; print(contextlib.__file__); print(contextlib.contextmanager.__code__.co_filename)" /home/ncoghlan/devel/cpython/Lib/contextlib.py /home/ncoghlan/devel/cpython/Lib/contextlib.py $ mkdir -p /tmp/example $ cd /tmp/example $ cp /home/ncoghlan/devel/cpython/Lib/__pycache__/contextlib.cpython-38.pyc contextlib.pyc $ /home/ncoghlan/devel/cpython/python -c "import contextlib; print(contextlib.__file__); print(contextlib.contextmanager.__code__.co_filename)" /tmp/example/contextlib.pyc /home/ncoghlan/devel/cpython/Lib/contextlib.py =========== ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue18307> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com