From 28b05829a358396dfa27e76d91a682a7c8bbc8ac Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Fri, 5 Jun 2020 12:29:33 +0200 Subject: fix(decorators): don't do magic on __doc__ when sphinx is called Otherwise donc cachedproperty.__doc__ returns "property" and not the expected docstring. --- logilab/common/decorators.py | 17 +++++++++++------ 1 file 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 "%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 "%s" % ("\n%s" % doc if doc else "") def __get__(self, inst, objtype=None): if inst is None: -- cgit v1.2.1