Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix code and test
  • Loading branch information
earias314 committed Sep 23, 2020
commit 54603eeffdb421a231c329119de22b411e8506d8
5 changes: 2 additions & 3 deletions Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1775,9 +1775,8 @@ def doc(thing, title='Python Library Documentation: %s', forceload=0,
output=None, follow_wrapped=True):
"""Display text documentation, given an object or a path to an object."""
try:
if follow_wrapped:
thing = inspect.unwrap(thing,
stop=(lambda func: not getattr(func, '__doc__', True)))
if not follow_wrapped:
thing = type(thing)
if output is None:
pager(render_doc(thing, title, forceload))
else:
Expand Down
21 changes: 12 additions & 9 deletions Lib/test/test_pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ def test_builtin_on_metaclasses(self):
# Testing that the subclasses section does not appear
self.assertNotIn('Built-in subclasses', text)

def test_builtin_with_wrapper(self):
def test_help_with_wrapper(self):
"""Test help on function wrapped.

When running help() on a function that is wrapped,
Expand All @@ -659,7 +659,7 @@ def test_builtin_with_wrapper(self):
class TestWrapper:
"""This is the docstring of Wrapper"""
def __init__(self, func):
functools.update_wrapper(func)
functools.update_wrapper(self, func)
def __call__(self):
pass

Expand All @@ -668,19 +668,22 @@ def test_func1():
"""Test func1"""
pass

doc = pydoc.TextDoc()
text = doc.docclass(test_func1)
self.assertIn('Test func1', text)
buff = StringIO()

helper = pydoc.Helper(output=buff)

helper.help(test_func1)
self.assertIn('Test func1', buff.getvalue().strip())

text = doc.docclass(test_func1, follow_wrapped=False)
self.assertIn("This is the docstring for Wrapper", text)
helper.help(test_func1, follow_wrapped=False)
self.assertIn("This is the docstring of Wrapper", buff.getvalue().strip())

@TestWrapper
def test_func2():
pass

text = doc.docclass(test_func1)
self.assertIn("This is the docstring for wrapper", text)
helper.help(test_func2)
self.assertIn("This is the docstring of Wrapper", buff.getvalue().strip())

@unittest.skipIf(sys.flags.optimize >= 2,
'Docstrings are omitted with -O2 and above')
Expand Down