Issue 8720: undo findsource regression/change (original) (raw)

Issue8720

Created on 2010-05-14 22:59 by hpk, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
findsource.patch hpk,2010-05-15 07:26 patch to Lib/inspect.py, relative to r311
getsourcfile.patch r.david.murray,2010-05-21 00:59
Messages (9)
msg105776 - (view) Author: holger krekel (hpk) Date: 2010-05-14 22:59
Somewhere between python 3.0.1 and 3.1.2 the behaviour of inspect.findsource changed: it does not find the source code anymore for a code object whose filename/source is in the linecache.cache because instead of the previous:: file = getsourcefile(object) or getfile(object) it only does now:: file = getsourcefile(object) IMO it is enough if findsource() raises if it can't eventually discover the source code - i don't see the need to do this ahead. In any case, the r312 findsource version requires an ugly work around within py.test in order for it to continue to be able to use the inspect module with dynamically compiled code. The underlying issue is that at code-compile time no sensible (PEP302 compliantly loaded) module can be constructed because this is only known at exec-time but this is not part of the test tool API and is done somewhere in user code. Proposed fix: revert to r301 behaviour and add back "or getfile(object)" to the first line of inspect.findsource()
msg105778 - (view) Author: Andreas Stührk (Trundle) * Date: 2010-05-14 23:47
This was changed due to issue #4050.
msg105780 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-05-15 01:36
As I remember it, #4050 was in turn caused by a change elsewhere in the codebase to using linecache where it wasn't used before. Regardless, though, the problem is that findsource doesn't produce an error when called on a binary module. It thinks it found the source code, but what it found was binary data. @holger: can you suggest an alternate fix to #4050?
msg105794 - (view) Author: holger krekel (hpk) Date: 2010-05-15 07:26
Thanks for helping with this! Attached is a patch that adds a keyword "check=True" to getsourcefile so that findsource can defer existence-checking until after cache lookup. Eventually, findsource will still raise an IOError if it can't find the source file and cannot recover the source from cache. The patch mainly consists of adding a number of tests to specify the (refined) behaviour of findsource and getsourcefile. best, holger
msg106209 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-05-21 00:59
Holger, what do you think of this alternate patch that instead makes getsourcefile smarter? It's a simpler patch and doesn't change the API, and your tests (suitably modified) pass.
msg106218 - (view) Author: holger krekel (hpk) Date: 2010-05-21 09:04
David, your getsourcefile.patch looks fine (and better than mine) to me.
msg106224 - (view) Author: holger krekel (hpk) Date: 2010-05-21 10:06
Well, maybe we could introduce a "linecache.setlines" function to give the linecache module control over its internal caching and data handling. What do you think?
msg107913 - (view) Author: holger krekel (hpk) Date: 2010-06-16 11:38
Seems the inspect.getsourcefile regression now is in the RC1 of Python2.7 as well. I suggest to apply the "getsourcefile.patch" patch which was attached from David. I tested it and it works fine for Python2.7 and Python3.1.
msg107986 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-06-17 02:07
I've applied the patch to trunk in r82039, to py3k in r82041, and 3.1 in r82042. Holger, I'm not really familiar with the linecache module and its uses, so I'm not sure what your proposal is aimed at. Perhaps you could flesh out your proposal in a new ticket?
History
Date User Action Args
2022-04-11 14:57:01 admin set github: 52966
2010-06-17 02:07:22 r.david.murray set status: pending -> closedversions: - Python 3.3messages: + assignee: r.david.murrayresolution: fixedstage: patch review -> resolved
2010-06-16 11:38:47 hpk set status: open -> pendingmessages: + versions: + Python 2.7, Python 3.3
2010-05-21 10:06:27 hpk set messages: +
2010-05-21 09:04:47 hpk set messages: +
2010-05-21 00:59:14 r.david.murray set files: + getsourcfile.patchmessages: + stage: patch review
2010-05-15 07:26:18 hpk set files: + findsource.patchkeywords: + patchmessages: +
2010-05-15 01:36:28 r.david.murray set messages: +
2010-05-15 00:47:16 pitrou set nosy: + r.david.murrayversions: + Python 3.2
2010-05-14 23:47:13 Trundle set nosy: + Trundlemessages: +
2010-05-14 22:59:53 hpk create