mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
inspect: Fix getsource() to load updated source of reloaded module
Issue #1218234. Initial patch by Berker Peksag.
This commit is contained in:
parent
f8b44a4f37
commit
7de29687f2
3 changed files with 46 additions and 6 deletions
|
@ -652,11 +652,17 @@ def findsource(object):
|
|||
in the file and the line number indexes a line in that list. An OSError
|
||||
is raised if the source code cannot be retrieved."""
|
||||
|
||||
file = getfile(object)
|
||||
sourcefile = getsourcefile(object)
|
||||
if not sourcefile and file[:1] + file[-1:] != '<>':
|
||||
raise OSError('source code not available')
|
||||
file = sourcefile if sourcefile else file
|
||||
file = getsourcefile(object)
|
||||
if file:
|
||||
# Invalidate cache if needed.
|
||||
linecache.checkcache(file)
|
||||
else:
|
||||
file = getfile(object)
|
||||
# Allow filenames in form of "<something>" to pass through.
|
||||
# `doctest` monkeypatches `linecache` module to enable
|
||||
# inspection, so let `linecache.getlines` to be called.
|
||||
if not (file.startswith('<') and file.endswith('>')):
|
||||
raise OSError('source code not available')
|
||||
|
||||
module = getmodule(object, file)
|
||||
if module:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue