-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Deprecate
no_docstring
argument for Documenter.add_content()
This deprecates `no_docstring` argument for Documenter.add_content(). After this change, please use Documenter.get_doc() to control (suppress) the content of the python object.
- Loading branch information
Showing
3 changed files
with
28 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -584,6 +584,11 @@ def get_sourcename(self) -> str: | |
def add_content(self, more_content: Optional[StringList], no_docstring: bool = False | ||
) -> None: | ||
"""Add content from docstrings, attribute documentation and user.""" | ||
if no_docstring: | ||
warnings.warn("The 'no_docstring' argument to %s.add_content() is deprecated." | ||
% self.__class__.__name__, | ||
RemovedInSphinx50Warning, stacklevel=2) | ||
|
||
# set sourcename and add content from attribute documentation | ||
sourcename = self.get_sourcename() | ||
if self.analyzer: | ||
|
@@ -1595,6 +1600,10 @@ def get_doc(self, encoding: str = None, ignore: int = None) -> List[List[str]]: | |
warnings.warn("The 'encoding' argument to autodoc.%s.get_doc() is deprecated." | ||
% self.__class__.__name__, | ||
RemovedInSphinx40Warning, stacklevel=2) | ||
if self.doc_as_attr: | ||
# Don't show the docstring of the class when it is an alias. | ||
return [] | ||
|
||
lines = getattr(self, '_new_docstrings', None) | ||
if lines is not None: | ||
return lines | ||
|
@@ -1641,10 +1650,9 @@ def get_doc(self, encoding: str = None, ignore: int = None) -> List[List[str]]: | |
def add_content(self, more_content: Optional[StringList], no_docstring: bool = False | ||
) -> None: | ||
if self.doc_as_attr: | ||
content = StringList([_('alias of %s') % restify(self.object)], source='') | ||
super().add_content(content, no_docstring=True) | ||
else: | ||
super().add_content(more_content) | ||
more_content = StringList([_('alias of %s') % restify(self.object)], source='') | ||
|
||
super().add_content(more_content) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
tk0miya
Author
Member
|
||
|
||
def document_members(self, all_members: bool = False) -> None: | ||
if self.doc_as_attr: | ||
|
@@ -1811,13 +1819,11 @@ def should_suppress_value_header(self) -> bool: | |
return (self.object == UNINITIALIZED_ATTR or | ||
super().should_suppress_value_header()) | ||
|
||
def add_content(self, more_content: Optional[StringList], no_docstring: bool = False | ||
) -> None: | ||
def get_doc(self, encoding: str = None, ignore: int = None) -> List[List[str]]: | ||
if self.object is UNINITIALIZED_ATTR: | ||
# suppress docstring of the value | ||
super().add_content(more_content, no_docstring=True) # type: ignore | ||
return [] | ||
else: | ||
super().add_content(more_content, no_docstring=no_docstring) # type: ignore | ||
return super().get_doc(encoding, ignore) # type: ignore | ||
|
||
|
||
class DataDocumenter(GenericAliasMixin, NewTypeMixin, TypeVarMixin, | ||
|
@@ -2220,6 +2226,11 @@ def add_directive_header(self, sig: str) -> None: | |
pass | ||
|
||
def get_doc(self, encoding: str = None, ignore: int = None) -> List[List[str]]: | ||
if not self._datadescriptor: | ||
# if it's not a data descriptor, its docstring is very probably the | ||
# wrong thing to display | ||
return [] | ||
|
||
try: | ||
# Disable `autodoc_inherit_docstring` temporarily to avoid to obtain | ||
# a docstring from the value which descriptor returns unexpectedly. | ||
|
@@ -2232,11 +2243,6 @@ def get_doc(self, encoding: str = None, ignore: int = None) -> List[List[str]]: | |
|
||
def add_content(self, more_content: Optional[StringList], no_docstring: bool = False | ||
) -> None: | ||
if not self._datadescriptor: | ||
# if it's not a data descriptor, its docstring is very probably the | ||
# wrong thing to display | ||
no_docstring = True | ||
|
||
if more_content is None: | ||
more_content = StringList() | ||
self.update_content(more_content) | ||
|
One consequence of this change is that now the
'autodoc-process-docstring'
event is called for the case ofdoc_as_attr
, while before this was not called.I am running into a problem with this with numpydoc, which then adds content for a class dostring to this
py:attribute
directive (because ofdoc_as_attr= True
, sphinx is using an attribute docstring instead of class docstring). And then later sphinx cannot parse this generated directive, because it cannot find members for an attribute ..Given that for the case of
doc_as_attr= True
a dummy docstring gets generated in a non-class directive, it's maybe best to continue not passing this to the'autodoc-process-docstring'
event?