[Python-checkins] cpython: Issue #21740: Support wrapped callables in pydoc. Patch by Claudiu Popa.

yury.selivanov python-checkins at python.org
Mon Dec 8 21:00:29 CET 2014


https://hg.python.org/cpython/rev/d22ca7496c54
changeset: 93791:d22ca7496c54
user: Yury Selivanov <yselivanov at sprymix.com>
date: Mon Dec 08 15:00:05 2014 -0500
summary:
 Issue #21740: Support wrapped callables in pydoc. Patch by Claudiu Popa.
files:
 Lib/doctest.py | 3 ++-
 Lib/test/test_doctest.py | 19 ++++++++++++++++++-
 Misc/NEWS | 2 ++
 3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/Lib/doctest.py b/Lib/doctest.py
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -985,7 +985,8 @@
 for valname, val in obj.__dict__.items():
 valname = '%s.%s' % (name, valname)
 # Recurse to functions & classes.
- if ((inspect.isroutine(val) or inspect.isclass(val)) and
+ if ((inspect.isroutine(inspect.unwrap(val))
+ or inspect.isclass(val)) and
 self._from_module(module, val)):
 self._find(tests, val, valname, module, source_lines,
 globs, seen)
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -4,6 +4,7 @@
 
 from test import support
 import doctest
+import functools
 import os
 import sys
 
@@ -434,7 +435,7 @@
 >>> tests = finder.find(sample_func)
 
 >>> print(tests) # doctest: +ELLIPSIS
- [<DocTest sample_func from ...:18 (1 example)>]
+ [<DocTest sample_func from ...:19 (1 example)>]
 
 The exact name depends on how test_doctest was invoked, so allow for
 leading path components.
@@ -2364,6 +2365,22 @@
 foo \n
 """
 
+class Wrapper:
+ def __init__(self, func):
+ self.func = func
+ functools.update_wrapper(self, func)
+
+ def __call__(self, *args, **kwargs):
+ self.func(*args, **kwargs)
+
+ at Wrapper
+def test_look_in_unwrapped():
+ """
+ Docstrings in wrapped functions must be detected as well.
+
+ >>> 'one other test'
+ 'one other test'
+ """
 
 def test_unittest_reportflags():
 """Default unittest reporting flags can be set to control reporting
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -194,6 +194,8 @@
 Library
 -------
 
+- Issue #21740: Support wrapped callables in pydoc. Patch by Claudiu Popa.
+
 - Issue #23009: Make sure selectors.EpollSelecrtor.select() works when no
 FD is registered.
 
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /