homepage

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 philipdumont
Recipients
Date 2007年03月09日.18:25:40
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
What I had in mind was something like changing:
 def getsourcefile(object):
 """Return the Python source file an object was defined in, if it exists."""
 filename = getfile(object)
 if string.lower(filename[-4:]) in ['.pyc', '.pyo']:
 filename = filename[:-4] + '.py'
 # ...the rest of the function...
to
 def getsourcefile(object):
 """Return the Python source file an object was defined in, if it exists."""
 filename = getfile(object)
 if string.lower(filename[-4:]) in ['.pyc', '.pyo']:
 src_filename = filename[:-4] + '.py'
 try:
 # if src file has been edited since we loaded the obj file, ignore it
 if os.stat(filename).st_mtime > os.stat(src_filename).st_mtime:
 filename = src_filename
 except OSError:
 pass
 # ...the rest of the function...
But now that I've tried to implement it, and thought about it a bit more, I see some
of the issues with what I thought would be a simple fix:
- I originally thought that, if a module is loaded from source (either because the
objfile did not exist, or because objfile was older), and the compiled src was successfully
written to a new objfile, that inspect.getfile() would return the path to the objfile.
I see now that that is not the case; it returns the srcfile. That makes my fix
a bit more difficult -- now you have to find out if there is an obj file, and if
so, what it's called.
And even if you had a handle on both the srcfile and the objfile:
- Even if the srcfile's timestamp is newer than the objfile's, it doesn't necessarily
mean that the srcfile has been edited since it was loaded. It could be that the srcfile
was already newer than the objfile before the module was loaded, so the module was
loaded from the srcfile, and the objfile was not updated because it was not writable by
the user.
- Even if the srcfile's timestamp is older than the objfile's, it doesn't necessarily
mean that the srcfile represents what you have loaded in memory. It could be that
after you loaded the module, your colleague down the hall edited the source, loaded
the module, and in the process was successful in updating the objfile. (Not a likely
scenario, but...)
- If the module was loaded from source, there was no objfile, and an objfile could not
be created because the directory was not writable, the fix doesn't help at all.
To be able to fix this right, you'd have to know what the timestamp was on whatever file
was loaded at the time that import loaded it. I guess import itself would have to stash
this away somewhere.
History
Date User Action Args
2007年08月23日 14:51:02adminlinkissue1628987 messages
2007年08月23日 14:51:02admincreate

AltStyle によって変換されたページ (->オリジナル) /