Merge pull request #6458 from tk0miya/6451_autodoc_optonal_imported_modules

Fix #6451: autodoc: generates docs for "optional import"ed modules as variables
This commit is contained in:
Takeshi KOMIYA 2019-06-10 02:49:14 +09:00 committed by GitHub
commit 2289ae0a11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View File

@ -19,6 +19,7 @@ Bugs fixed
* #6442: LaTeX: admonitions of :rst:dir:`note` type can get separated from
immediately preceding section title by pagebreak
* #6448: autodoc: crashed when autodocumenting classes with ``__slots__ = None``
* #6451: autodoc: generates docs for "optional import"ed modules as variables
* #6452: autosummary: crashed when generating document of properties
* #6455: napoleon: docstrings for properties are not processed
* #6436: napoleon: "Unknown target name" error if variable name ends with

View File

@ -357,6 +357,17 @@ class VariableCommentPicker(ast.NodeVisitor):
except TypeError:
pass # this assignment is not new definition!
def visit_Try(self, node):
# type: (ast.Try) -> None
"""Handles Try node and processes body and else-clause.
.. note:: pycode parser ignores objects definition in except-clause.
"""
for subnode in node.body:
self.visit(subnode)
for subnode in node.orelse:
self.visit(subnode)
def visit_ClassDef(self, node):
# type: (ast.ClassDef) -> None
"""Handles ClassDef node and set context."""

View File

@ -149,6 +149,21 @@ def test_complex_assignment_py3():
assert parser.definitions == {}
def test_assignment_in_try_clause():
source = ('try:\n'
' a = None #: comment\n'
'except:\n'
' b = None #: ignored\n'
'else:\n'
' c = None #: comment\n')
parser = Parser(source)
parser.parse()
assert parser.comments == {('', 'a'): 'comment',
('', 'c'): 'comment'}
assert parser.deforders == {'a': 0,
'c': 1}
def test_obj_assignment():
source = ('obj = SomeObject() #: some object\n'
'obj.attr = 1 #: attr1\n'