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
b64f85e5
Commit
b64f85e5
authored
Feb 20, 2015
by
Berker Peksag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #21548: Fix pydoc.synopsis() and pydoc.apropos() on modules with empty
docstrings. Initial patch by Yuyang Guo.
parent
b695dcb6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
2 deletions
+34
-2
Lib/pydoc.py
Lib/pydoc.py
+2
-2
Lib/test/test_pydoc.py
Lib/test/test_pydoc.py
+29
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/pydoc.py
View file @
b64f85e5
...
...
@@ -255,7 +255,7 @@ def synopsis(filename, cache={}):
if
info
and
'b'
in
info
[
2
]:
# binary modules have to be imported
try
:
module
=
imp
.
load_module
(
'__temp__'
,
file
,
filename
,
info
[
1
:])
except
:
return
None
result
=
(
module
.
__doc__
or
''
).
splitlines
()[
0
]
result
=
module
.
__doc__
.
splitlines
()[
0
]
if
module
.
__doc__
else
None
del
sys
.
modules
[
'__temp__'
]
else
:
# text modules can be directly examined
result
=
source_synopsis
(
file
)
...
...
@@ -2020,7 +2020,7 @@ class ModuleScanner:
path
=
None
else
:
module
=
loader
.
load_module
(
modname
)
desc
=
(
module
.
__doc__
or
''
).
splitlines
()[
0
]
desc
=
module
.
__doc__
.
splitlines
()[
0
]
if
module
.
__doc__
else
''
path
=
getattr
(
module
,
'__file__'
,
None
)
if
find
(
lower
(
modname
+
' - '
+
desc
),
key
)
>=
0
:
callback
(
path
,
modname
,
desc
)
...
...
Lib/test/test_pydoc.py
View file @
b64f85e5
...
...
@@ -3,6 +3,7 @@ import sys
import
difflib
import
__builtin__
import
re
import
py_compile
import
pydoc
import
contextlib
import
inspect
...
...
@@ -382,6 +383,34 @@ class PydocDocTest(unittest.TestCase):
self
.
assertEqual
(
stripid
(
"<type 'exceptions.Exception'>"
),
"<type 'exceptions.Exception'>"
)
def
test_synopsis
(
self
):
with
test
.
test_support
.
temp_cwd
()
as
test_dir
:
init_path
=
os
.
path
.
join
(
test_dir
,
'dt.py'
)
with
open
(
init_path
,
'w'
)
as
fobj
:
fobj
.
write
(
'''
\
"""
my doc
second line
"""
foo = 1
'''
)
py_compile
.
compile
(
init_path
)
synopsis
=
pydoc
.
synopsis
(
init_path
,
{})
self
.
assertEqual
(
synopsis
,
'my doc'
)
def
test_synopsis_sourceless_empty_doc
(
self
):
with
test
.
test_support
.
temp_cwd
()
as
test_dir
:
init_path
=
os
.
path
.
join
(
test_dir
,
'foomod42.py'
)
cached_path
=
os
.
path
.
join
(
test_dir
,
'foomod42.pyc'
)
with
open
(
init_path
,
'w'
)
as
fobj
:
fobj
.
write
(
"foo = 1"
)
py_compile
.
compile
(
init_path
)
synopsis
=
pydoc
.
synopsis
(
init_path
,
{})
self
.
assertIsNone
(
synopsis
)
synopsis_cached
=
pydoc
.
synopsis
(
cached_path
,
{})
self
.
assertIsNone
(
synopsis_cached
)
class
PydocImportTest
(
PydocBaseTest
):
...
...
Misc/NEWS
View file @
b64f85e5
...
...
@@ -18,6 +18,9 @@ Core and Builtins
Library
-------
- Issue #21548: Fix pydoc.synopsis() and pydoc.apropos() on modules with empty
docstrings. Initial patch by Yuyang Guo.
- Issue #22885: Fixed arbitrary code execution vulnerability in the dumbdbm
module. Original patch by Claudiu Popa.
...
...
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