This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients Mariatta, brett.cannon, christian.heimes, ncoghlan, serhiy.storchaka, twouters, vmurashev
Date 2018-09-02.16:47:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1535906832.77.0.56676864532.issue18307@psf.upfronthosting.co.za>
In-reply-to
Content
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
===========
History
Date User Action Args
2018-09-02 16:47:12ncoghlansetrecipients: + ncoghlan, twouters, brett.cannon, christian.heimes, serhiy.storchaka, vmurashev, Mariatta
2018-09-02 16:47:12ncoghlansetmessageid: <1535906832.77.0.56676864532.issue18307@psf.upfronthosting.co.za>
2018-09-02 16:47:12ncoghlanlinkissue18307 messages
2018-09-02 16:47:12ncoghlancreate