summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2014-12-08 23:00:25 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2014-12-08 23:00:25 (GMT)
commit7de29687f22fff5c38ca252de4167e043b28e470 (patch)
treecc5767d1340db76bfe1ac63e542a668a3a25826b /Lib/inspect.py
parentf8b44a4f37e1885e7dd8d4e4e921e207f7102dd3 (diff)
downloadcpython-7de29687f22fff5c38ca252de4167e043b28e470.zip
cpython-7de29687f22fff5c38ca252de4167e043b28e470.tar.gz
cpython-7de29687f22fff5c38ca252de4167e043b28e470.tar.bz2
inspect: Fix getsource() to load updated source of reloaded module
Issue #1218234. Initial patch by Berker Peksag.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 530f240..1641824 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -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: