mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
gh-136914: Fix support of cached functions and properties in DocTest's lineno computation (GH-136930)
Previously, DocTest's lineno of functions and methods decorated with functools.cache(), functools.lru_cache() and functools.cached_property() was not properly returned (None was returned) because the computation relied on inspect.isfunction() which does not consider the decorated result as a function. We now use the more generic inspect.isroutine(), as elsewhere in doctest's logic. Also, added a special case for functools.cached_property().
This commit is contained in:
parent
d5e75c0768
commit
fece15d29f
4 changed files with 39 additions and 1 deletions
|
|
@ -94,6 +94,7 @@ def _test():
|
|||
|
||||
import __future__
|
||||
import difflib
|
||||
import functools
|
||||
import inspect
|
||||
import linecache
|
||||
import os
|
||||
|
|
@ -1141,7 +1142,9 @@ def _find_lineno(self, obj, source_lines):
|
|||
if inspect.ismethod(obj): obj = obj.__func__
|
||||
if isinstance(obj, property):
|
||||
obj = obj.fget
|
||||
if inspect.isfunction(obj) and getattr(obj, '__doc__', None):
|
||||
if isinstance(obj, functools.cached_property):
|
||||
obj = obj.func
|
||||
if inspect.isroutine(obj) and getattr(obj, '__doc__', None):
|
||||
# We don't use `docstring` var here, because `obj` can be changed.
|
||||
obj = inspect.unwrap(obj)
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue