Merge pull request #8633 from tk0miya/merge_3.4.x

Merge 3.4.x to 3.x
This commit is contained in:
Takeshi KOMIYA
2021-01-01 13:11:56 +09:00
committed by GitHub
3 changed files with 43 additions and 4 deletions

View File

@@ -58,6 +58,10 @@ Bugs fixed
----------
* #8164: autodoc: Classes that inherit mocked class are not documented
* #8602: autodoc: The ``autodoc-process-docstring`` event is emitted to the
non-datadescriptors unexpectedly
* #8616: autodoc: AttributeError is raised on non-class object is passed to
autoclass directive
Testing
--------

View File

@@ -1694,7 +1694,10 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type:
def add_content(self, more_content: Optional[StringList], no_docstring: bool = False
) -> None:
if self.doc_as_attr:
try:
more_content = StringList([_('alias of %s') % restify(self.object)], source='')
except AttributeError:
pass # Invalid class object is passed.
super().add_content(more_content)
@@ -2160,15 +2163,24 @@ class NonDataDescriptorMixin(DataDocumenterMixinBase):
and :value: header will be suppressed unexpectedly.
"""
def import_object(self, raiseerror: bool = False) -> bool:
ret = super().import_object(raiseerror) # type: ignore
if ret and not inspect.isattributedescriptor(self.object):
self.non_data_descriptor = True
else:
self.non_data_descriptor = False
return ret
def should_suppress_value_header(self) -> bool:
return (inspect.isattributedescriptor(self.object) or
return (not getattr(self, 'non_data_descriptor', False) or
super().should_suppress_directive_header())
def get_doc(self, encoding: str = None, ignore: int = None) -> Optional[List[List[str]]]:
if not inspect.isattributedescriptor(self.object):
if getattr(self, 'non_data_descriptor', False):
# the docstring of non datadescriptor is very probably the wrong thing
# to display
return []
return None
else:
return super().get_doc(encoding, ignore) # type: ignore
@@ -2321,6 +2333,12 @@ class UninitializedInstanceAttributeMixin(DataDocumenterMixinBase):
return (self.object is UNINITIALIZED_ATTR or
super().should_suppress_value_header())
def get_doc(self, encoding: str = None, ignore: int = None) -> Optional[List[List[str]]]:
if self.object is UNINITIALIZED_ATTR:
return None
else:
return super().get_doc(encoding, ignore) # type: ignore
class AttributeDocumenter(GenericAliasMixin, NewTypeMixin, SlotsMixin, # type: ignore
TypeVarMixin, RuntimeInstanceAttributeMixin,

View File

@@ -34,6 +34,23 @@ def test_process_docstring(app):
]
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_process_docstring_for_nondatadescriptor(app):
def on_process_docstring(app, what, name, obj, options, lines):
raise
app.connect('autodoc-process-docstring', on_process_docstring)
actual = do_autodoc(app, 'attribute', 'target.AttCls.a1')
assert list(actual) == [
'',
'.. py:attribute:: AttCls.a1',
' :module: target',
' :value: hello world',
'',
]
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_cut_lines(app):
app.connect('autodoc-process-docstring',