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
54237f9f
Commit
54237f9f
authored
Feb 16, 2015
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix pydoc.apropos and pydoc.synopsis on modules with empty docstrings (#21548)
Patch by Yuyang Guo and Berker Peksag.
parent
3584056c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
2 deletions
+38
-2
Lib/pydoc.py
Lib/pydoc.py
+2
-2
Lib/test/test_pydoc.py
Lib/test/test_pydoc.py
+32
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/pydoc.py
View file @
54237f9f
...
...
@@ -270,7 +270,7 @@ def synopsis(filename, cache={}):
except
:
return
None
del
sys
.
modules
[
'__temp__'
]
result
=
(
module
.
__doc__
or
''
).
splitlines
()[
0
]
result
=
module
.
__doc__
.
splitlines
()[
0
]
if
module
.
__doc__
else
None
# Cache the result.
cache
[
filename
]
=
(
mtime
,
result
)
return
result
...
...
@@ -2075,7 +2075,7 @@ class ModuleScanner:
if
onerror
:
onerror
(
modname
)
continue
desc
=
(
module
.
__doc__
or
''
).
splitlines
()[
0
]
desc
=
module
.
__doc__
.
splitlines
()[
0
]
if
module
.
__doc__
else
''
path
=
getattr
(
module
,
'__file__'
,
None
)
name
=
modname
+
' - '
+
desc
if
name
.
lower
().
find
(
key
)
>=
0
:
...
...
Lib/test/test_pydoc.py
View file @
54237f9f
...
...
@@ -3,12 +3,15 @@ import sys
import
builtins
import
contextlib
import
difflib
import
importlib.util
import
inspect
import
pydoc
import
py_compile
import
keyword
import
_pickle
import
pkgutil
import
re
import
stat
import
string
import
test.support
import
time
...
...
@@ -557,6 +560,18 @@ class PydocDocTest(unittest.TestCase):
self
.
assertEqual
(
synopsis
,
expected
)
def
test_synopsis_sourceless_empty_doc
(
self
):
with
test
.
support
.
temp_cwd
()
as
test_dir
:
init_path
=
os
.
path
.
join
(
test_dir
,
'foomod42.py'
)
cached_path
=
importlib
.
util
.
cache_from_source
(
init_path
)
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
)
def
test_splitdoc_with_description
(
self
):
example_string
=
"I Am A Doc
\
n
\
n
\
n
Here is my description"
self
.
assertEqual
(
pydoc
.
splitdoc
(
example_string
),
...
...
@@ -612,6 +627,7 @@ class PydocImportTest(PydocBaseTest):
def
setUp
(
self
):
self
.
test_dir
=
os
.
mkdir
(
TESTFN
)
self
.
addCleanup
(
rmtree
,
TESTFN
)
importlib
.
invalidate_caches
()
def
test_badimport
(
self
):
# This tests the fix for issue 5230, where if pydoc found the module
...
...
@@ -670,6 +686,22 @@ class PydocImportTest(PydocBaseTest):
self
.
assertEqual
(
out
.
getvalue
(),
''
)
self
.
assertEqual
(
err
.
getvalue
(),
''
)
def
test_apropos_empty_doc
(
self
):
pkgdir
=
os
.
path
.
join
(
TESTFN
,
'walkpkg'
)
os
.
mkdir
(
pkgdir
)
self
.
addCleanup
(
rmtree
,
pkgdir
)
init_path
=
os
.
path
.
join
(
pkgdir
,
'__init__.py'
)
with
open
(
init_path
,
'w'
)
as
fobj
:
fobj
.
write
(
"foo = 1"
)
current_mode
=
stat
.
S_IMODE
(
os
.
stat
(
pkgdir
).
st_mode
)
try
:
os
.
chmod
(
pkgdir
,
current_mode
&
~
stat
.
S_IEXEC
)
with
self
.
restrict_walk_packages
(
path
=
[
TESTFN
]),
captured_stdout
()
as
stdout
:
pydoc
.
apropos
(
''
)
self
.
assertIn
(
'walkpkg'
,
stdout
.
getvalue
())
finally
:
os
.
chmod
(
pkgdir
,
current_mode
)
@
unittest
.
skip
(
'causes undesireable side-effects (#20128)'
)
def
test_modules
(
self
):
# See Helper.listmodules().
...
...
Misc/ACKS
View file @
54237f9f
...
...
@@ -506,6 +506,7 @@ Eric Groo
Dag Gruneau
Filip Gruszczyński
Thomas Guettler
Yuyang Guo
Anuj Gupta
Michael Guravage
Lars Gustäbel
...
...
Misc/NEWS
View file @
54237f9f
...
...
@@ -13,6 +13,9 @@ Core and Builtins
Library
-------
- Issue #21548: Fix pydoc.synopsis() and pydoc.apropos() on modules with empty
docstrings.
- Issue #22885: Fixed arbitrary code execution vulnerability in the dbm.dumb
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