classification
Title: Clean up tests for pyc/pyo in __file__
Type: Stage: resolved
Components: Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: barry, benjamin.peterson, eric.araujo, python-dev, r.david.murray, vinay.sajip
Priority: normal Keywords: patch

Created on 2011-08-18 17:14 by eric.araujo, last changed 2014-10-03 15:20 by r.david.murray. This issue is now closed.

Files
File name Uploaded Description Edit
__file__-cant-contain-pyc-in-3.2.diff eric.araujo, 2011-08-18 17:34
Messages (7)
msg142375 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-08-18 17:14
After PEP 3147, __file__ always points to the py file, not pyc/pyo.  I found two instances of obsolete code.
msg142416 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-08-19 06:15
New changeset 98d13885a574 by Vinay Sajip in branch '3.2':
Issue #12780: Removed checks in logging for .pyc/.pyo in __file__.
http://hg.python.org/cpython/rev/98d13885a574

New changeset ac0c04d8eafb by Vinay Sajip in branch 'default':
Issue #12780: Merged fix from 3.2.
http://hg.python.org/cpython/rev/ac0c04d8eafb
msg142612 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-08-21 12:00
Barry, could you review the second part of the patch?  (the first was committed)
msg142693 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2011-08-22 08:02
Seems reasonable to me.  When did/does unicodedata ever have a __file__ attribute?
msg147844 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-11-18 10:15
> Seems reasonable to me.  When did/does unicodedata ever have a __file__ attribute?
No idea.  Maybe it has to do with static vs. dynamic linking?  Or alternate VMs?
msg228328 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-10-03 15:17
New changeset 1745fd612d73 by R David Murray in branch '3.4':
#12780: update inspect test skipIf for PEP 3147.
https://hg.python.org/cpython/rev/1745fd612d73

New changeset 8120de25932f by R David Murray in branch 'default':
Merge: #12780: update inspect test skipIf for PEP 3147.
https://hg.python.org/cpython/rev/8120de25932f
msg228329 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-10-03 15:19
It is not true that __file__ will always end with '.py'.  If *only* the .pyc or .pyo file exists (not the PEP 3147 version, but just modname.pyc on the pythonpath), then __file__ will end with .pyc.  It is also the case that __file__ may end with something *else*, such as .so on unix and .pyd on Windows, as it does in this particular case.

So, dropping the extension check is the wrong logic fix.  The correct fix is to make sure it isn't '.py', because the original check was making sure there wasn't source code to load.  When might unicodedata be a python file and not a sourceless (from inspect's point of view) binary?  pypy :)  I have no idea if this is actually an issue on pypy, but I'd hate to introduce a new failure for them in the process of doing a cleanup.

The reason for the __file__ check is that we are looking for an *external* compiled module for the test.  Originally I used time, but that failed on windows because time is part of the main binary on windows and has no __file__ attribute.  The idea behind doing the __file__ check is that someone re-packaging python might move unicodedata into the main binary on windows, since if I understand correctly which modules are included there is somewhat arbitrary.
History
Date User Action Args
2014-10-03 15:20:00r.david.murraysetstatus: open -> closed

versions: + Python 3.4, Python 3.5, - Python 3.2, Python 3.3
nosy: + r.david.murray

messages: + msg228329
resolution: fixed
stage: commit review -> resolved
2014-10-03 15:17:07python-devsetmessages: + msg228328
2011-11-18 10:15:21eric.araujosetmessages: + msg147844
2011-08-22 08:02:37barrysetmessages: + msg142693
2011-08-21 12:00:01eric.araujosetnosy: + barry

messages: + msg142612
versions: + Python 3.2
2011-08-19 06:15:55python-devsetnosy: + python-dev
messages: + msg142416
2011-08-18 17:34:49eric.araujosetfiles: + __file__-cant-contain-pyc-in-3.2.diff
2011-08-18 17:34:39eric.araujosetfiles: - fix-11599.diff
2011-08-18 17:14:40eric.araujocreate