def test_getdoc_inherited_decorated_method(): class Foo: def meth(self): """docstring.""" class Bar(Foo): @functools.lru_cache() def meth(self): # inherited and decorated method pass assert inspect.getdoc(Bar.meth, getattr, False, Bar, "meth") is None assert inspect.getdoc(Bar.meth, getattr, True, Bar, "meth") == "docstring."
def add_content(self, more_content: Any, no_docstring: bool = False): """ Add the autodocumenter content. :param more_content: :param no_docstring: """ super().add_content(more_content=more_content, no_docstring=no_docstring) sourcename = self.get_sourcename() if not getdoc(self.object) and "show-inheritance" not in self.options: self.add_line(":class:`typing.Protocol`.", sourcename) self.add_line('', sourcename) if hasattr( self.object, "_is_runtime_protocol") and self.object._is_runtime_protocol: self.add_line(runtime_message, sourcename) self.add_line('', sourcename) self.add_line( "Classes that implement this protocol must have the following methods / attributes:", sourcename) self.add_line('', sourcename)
def test_getdoc_inherited_classmethod(): class Foo: @classmethod def meth(self): """ docstring indented text """ class Bar(Foo): @classmethod def meth(self): # inherited classmethod pass assert inspect.getdoc(Bar.meth, getattr, False, Bar, "meth") is None assert inspect.getdoc(Bar.meth, getattr, True, Bar, "meth") == Foo.meth.__doc__
def get_doc(self, encoding=None, ignore=1): """This patch prevents autodata object instances from having the docstrings of their classes""" docstring = getdoc(self.object, self.get_attr, self.env.config.autodoc_inherit_docstrings) obj_type_doc = getattr(type(self.object), '__doc__', None) if docstring == obj_type_doc: docstring = None if docstring: tab_width = self.directive.state.document.settings.tab_width return [prepare_docstring(docstring, ignore, tab_width)] return []
def add_content(self, more_content: Any, no_docstring: bool = False): """ Add the autodocumenter content. :param more_content: :param no_docstring: """ super().add_content(more_content=more_content, no_docstring=no_docstring) if not getdoc(self.object): sourcename = self.get_sourcename() self.add_line(":class:`typing.TypedDict`.", sourcename) self.add_line('', sourcename)
def get_doc(self, encoding=None, ignore=1): docstring = getdoc(self.object.descriptor.rules_func, self.get_attr, self.env.config.autodoc_inherit_docstrings) return [prepare_docstring(docstring, ignore)] if docstring else []