Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
703f7c4b
Commit
703f7c4b
authored
Jun 11, 2011
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Plain Diff
merge 3.2 (#9284)
parents
3ae42726
9620cc04
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
2 deletions
+26
-2
Lib/inspect.py
Lib/inspect.py
+6
-2
Lib/test/test_inspect.py
Lib/test/test_inspect.py
+17
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/inspect.py
View file @
703f7c4b
...
...
@@ -518,9 +518,13 @@ def findsource(object):
or code object. The source code is returned as a list of all the lines
in the file and the line number indexes a line in that list. An IOError
is raised if the source code cannot be retrieved."""
file
=
getsourcefile
(
object
)
if
not
file
:
file
=
getfile
(
object
)
sourcefile
=
getsourcefile
(
object
)
if
not
sourcefile
and
file
[
0
]
+
file
[
-
1
]
!=
'<>'
:
raise
IOError
(
'source code not available'
)
file
=
sourcefile
if
sourcefile
else
file
module
=
getmodule
(
object
,
file
)
if
module
:
lines
=
linecache
.
getlines
(
file
,
module
.
__dict__
)
...
...
Lib/test/test_inspect.py
View file @
703f7c4b
...
...
@@ -298,6 +298,23 @@ class TestRetrievingSourceCode(GetSourceBase):
del
sys
.
modules
[
name
]
inspect
.
getmodule
(
compile
(
'a=10'
,
''
,
'single'
))
def
test_proceed_with_fake_filename
(
self
):
'''doctest monkeypatches linecache to enable inspection'''
fn
,
source
=
'<test>'
,
'def x(): pass
\
n
'
getlines
=
linecache
.
getlines
def
monkey
(
filename
,
module_globals
=
None
):
if
filename
==
fn
:
return
source
.
splitlines
(
True
)
else
:
return
getlines
(
filename
,
module_globals
)
linecache
.
getlines
=
monkey
try
:
ns
=
{}
exec
(
compile
(
source
,
fn
,
'single'
),
ns
)
inspect
.
getsource
(
ns
[
"x"
])
finally
:
linecache
.
getlines
=
getlines
class
TestDecorators
(
GetSourceBase
):
fodderModule
=
mod2
...
...
Misc/NEWS
View file @
703f7c4b
...
...
@@ -190,6 +190,9 @@ Library
- Issue #12240: Allow multiple setup hooks in packaging'
s
setup
.
cfg
files
.
Original
patch
by
Erik
Bray
.
-
Issue
#
9284
:
Allow
inspect
.
findsource
()
to
find
the
source
of
doctest
functions
.
-
Issue
#
11595
:
Fix
assorted
bugs
in
packaging
.
util
.
cfg_to_args
,
a
compatibility
helper
for
the
distutils
-
packaging
transition
.
Original
patch
by
Erik
Bray
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment