summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Peuch <cortex@worlddomination.be>2020-06-05 12:29:33 +0200
committerLaurent Peuch <cortex@worlddomination.be>2020-06-05 12:29:33 +0200
commit28b05829a358396dfa27e76d91a682a7c8bbc8ac (patch)
treedb919e693ce6246b27d3ddfccaaf18a0b91d0706
parent8f776029a73015e74424fd01925f2f12bbb99724 (diff)
downloadlogilab-common-28b05829a358396dfa27e76d91a682a7c8bbc8ac.tar.gz
fix(decorators): don't do magic on __doc__ when sphinx is called
Otherwise donc cachedproperty.__doc__ returns "property" and not the expected docstring.
-rw-r--r--logilab/common/decorators.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/logilab/common/decorators.py b/logilab/common/decorators.py
index b7228e9..3367e16 100644
--- a/logilab/common/decorators.py
+++ b/logilab/common/decorators.py
@@ -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: