| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d5e75c0 commit fece15d
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -94,6 +94,7 @@ def _test(): | |||
| 94 | 94 | ||
| 95 | 95 | import __future__ | |
| 96 | 96 | import difflib | |
| 97 | + import functools | ||
| 97 | 98 | import inspect | |
| 98 | 99 | import linecache | |
| 99 | 100 | import os | |
@@ -1141,7 +1142,9 @@ def _find_lineno(self, obj, source_lines): | |||
| 1141 | 1142 | if inspect.ismethod(obj): obj = obj.__func__ | |
| 1142 | 1143 | if isinstance(obj, property): | |
| 1143 | 1144 | obj = obj.fget | |
| 1144 | - if inspect.isfunction(obj) and getattr(obj, '__doc__', None): | ||
| 1145 | + if isinstance(obj, functools.cached_property): | ||
| 1146 | + obj = obj.func | ||
| 1147 | + if inspect.isroutine(obj) and getattr(obj, '__doc__', None): | ||
| 1145 | 1148 | # We don't use `docstring` var here, because `obj` can be changed. | |
| 1146 | 1149 | obj = inspect.unwrap(obj) | |
| 1147 | 1150 | try: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,3 +76,32 @@ def property_with_doctest(self): | |||
| 76 | 76 | @decorator | |
| 77 | 77 | def func_with_docstring_wrapped(): | |
| 78 | 78 | """Some unrelated info.""" | |
| 79 | + | ||
| 80 | + | ||
| 81 | + # https://github.com/python/cpython/issues/136914 | ||
| 82 | + import functools | ||
| 83 | + | ||
| 84 | + | ||
| 85 | + @functools.cache | ||
| 86 | + def cached_func_with_doctest(value): | ||
| 87 | + """ | ||
| 88 | + >>> cached_func_with_doctest(1) | ||
| 89 | + -1 | ||
| 90 | + """ | ||
| 91 | + return -value | ||
| 92 | + | ||
| 93 | + | ||
| 94 | + @functools.cache | ||
| 95 | + def cached_func_without_docstring(value): | ||
| 96 | + return value + 1 | ||
| 97 | + | ||
| 98 | + | ||
| 99 | + class ClassWithACachedProperty: | ||
| 100 | + | ||
| 101 | + @functools.cached_property | ||
| 102 | + def cached(self): | ||
| 103 | + """ | ||
| 104 | + >>> X().cached | ||
| 105 | + -1 | ||
| 106 | + """ | ||
| 107 | + return 0 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -678,6 +678,8 @@ def basics(): r""" | |||
| 678 | 678 | >>> for t in tests: | |
| 679 | 679 | ... print('%5s %s' % (t.lineno, t.name)) | |
| 680 | 680 | None test.test_doctest.doctest_lineno | |
| 681 | + None test.test_doctest.doctest_lineno.ClassWithACachedProperty | ||
| 682 | + 102 test.test_doctest.doctest_lineno.ClassWithACachedProperty.cached | ||
| 681 | 683 | 22 test.test_doctest.doctest_lineno.ClassWithDocstring | |
| 682 | 684 | 30 test.test_doctest.doctest_lineno.ClassWithDoctest | |
| 683 | 685 | None test.test_doctest.doctest_lineno.ClassWithoutDocstring | |
@@ -687,6 +689,8 @@ def basics(): r""" | |||
| 687 | 689 | 45 test.test_doctest.doctest_lineno.MethodWrapper.method_with_doctest | |
| 688 | 690 | None test.test_doctest.doctest_lineno.MethodWrapper.method_without_docstring | |
| 689 | 691 | 61 test.test_doctest.doctest_lineno.MethodWrapper.property_with_doctest | |
| 692 | + 86 test.test_doctest.doctest_lineno.cached_func_with_doctest | ||
| 693 | + None test.test_doctest.doctest_lineno.cached_func_without_docstring | ||
| 690 | 694 | 4 test.test_doctest.doctest_lineno.func_with_docstring | |
| 691 | 695 | 77 test.test_doctest.doctest_lineno.func_with_docstring_wrapped | |
| 692 | 696 | 12 test.test_doctest.doctest_lineno.func_with_doctest | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Fix retrieval of :attr:`doctest.DocTest.lineno` for objects decorated with | ||
| 2 | + :func:`functools.cache` or :class:`functools.cached_property`. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments