Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b532df6

Browse files
committed
Issue #21740: Support wrapped callables in pydoc. Patch by Claudiu Popa.
1 parent a49d6a2 commit b532df6

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

Lib/doctest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,8 @@ def _find(self, tests, obj, name, module, source_lines, globs, seen):
985985
for valname, val in obj.__dict__.items():
986986
valname = '%s.%s' % (name, valname)
987987
# Recurse to functions & classes.
988-
if ((inspect.isroutine(val) or inspect.isclass(val)) and
988+
if ((inspect.isroutine(inspect.unwrap(val))
989+
or inspect.isclass(val)) and
989990
self._from_module(module, val)):
990991
self._find(tests, val, valname, module, source_lines,
991992
globs, seen)

Lib/test/test_doctest.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from test import support
66
import doctest
7+
import functools
78
import os
89
import sys
910

@@ -434,7 +435,7 @@ def basics(): r"""
434435
>>> tests = finder.find(sample_func)
435436
436437
>>> print(tests) # doctest: +ELLIPSIS
437-
[<DocTest sample_func from ...:18 (1 example)>]
438+
[<DocTest sample_func from ...:19 (1 example)>]
438439
439440
The exact name depends on how test_doctest was invoked, so allow for
440441
leading path components.
@@ -2364,6 +2365,22 @@ def test_trailing_space_in_test():
23642365
foo \n
23652366
"""
23662367

2368+
class Wrapper:
2369+
def __init__(self, func):
2370+
self.func = func
2371+
functools.update_wrapper(self, func)
2372+
2373+
def __call__(self, *args, **kwargs):
2374+
self.func(*args, **kwargs)
2375+
2376+
@Wrapper
2377+
def test_look_in_unwrapped():
2378+
"""
2379+
Docstrings in wrapped functions must be detected as well.
2380+
2381+
>>> 'one other test'
2382+
'one other test'
2383+
"""
23672384

23682385
def test_unittest_reportflags():
23692386
"""Default unittest reporting flags can be set to control reporting

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ Core and Builtins
194194
Library
195195
-------
196196

197+
- Issue #21740: Support wrapped callables in pydoc. Patch by Claudiu Popa.
198+
197199
- Issue #23009: Make sure selectors.EpollSelecrtor.select() works when no
198200
FD is registered.
199201

0 commit comments

Comments
 (0)