Skip to content

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/doctest_docutils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import doctest
2+
import functools
23
import linecache
34
import logging
45
import os
@@ -362,6 +363,27 @@ def condition(node: Node) -> bool:
362363
if test is not None:
363364
tests.append(test)
364365

366+
if sys.version_info < (3, 13):
367+
368+
def _from_module(
369+
self, module: t.Optional[t.Union[str, types.ModuleType]], object: object
370+
) -> bool:
371+
"""`cached_property` objects are never considered a part
372+
of the 'current module'. As such they are skipped by doctest.
373+
Here we override `_from_module` to check the underlying
374+
function instead. https://github.com/python/cpython/issues/107995
375+
"""
376+
if isinstance(object, functools.cached_property):
377+
object = object.func
378+
379+
# Type ignored because this is a private function.
380+
return t.cast(
381+
bool, super()._from_module(module, object) # type:ignore[misc]
382+
)
383+
384+
else: # pragma: no cover
385+
pass
386+
365387
def _get_test(
366388
self,
367389
string: str,

0 commit comments

Comments
 (0)