Commit 205233d6 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

fix(decorators): don't do magic on __doc__ when sphinx is called

Otherwise donc cachedproperty.__doc__ returns "property" and not the expected docstring.
parent 24baf06652b9
Pipeline #8686 passed with stages
in 5 minutes and 32 seconds
......@@ -21,6 +21,9 @@ from __future__ import print_function
__docformat__ = "restructuredtext en"
import os
import sys
from time import process_time, time
from inspect import isgeneratorfunction
from typing import Any, Optional, Callable, Union
......@@ -155,12 +158,14 @@ class cachedproperty(object):
raise TypeError("%s must have a __name__ attribute" % wrapped)
self.wrapped = wrapped
# mypy: Signature of "__doc__" incompatible with supertype "object"
# but this works?
@property
def __doc__(self) -> str: # type: ignore
doc = getattr(self.wrapped, "__doc__", None)
return "<wrapped by the cachedproperty decorator>%s" % ("\n%s" % doc if doc else "")
# otherwise this breaks sphinx static analysis for __doc__
if os.path.basename(sys.argv[0]) != "sphinx-build":
# mypy: Signature of "__doc__" incompatible with supertype "object"
# but this works?
@property
def __doc__(self) -> str: # type: ignore
doc = getattr(self.wrapped, "__doc__", None)
return "<wrapped by the cachedproperty decorator>%s" % ("\n%s" % doc if doc else "")
def __get__(self, inst, objtype=None):
if inst is None:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment