mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #6451: autodoc: generates docs for "optional import"ed modules as variables
This commit is contained in:
1
CHANGES
1
CHANGES
@@ -20,6 +20,7 @@ Bugs fixed
|
|||||||
immediately preceding section title by pagebreak
|
immediately preceding section title by pagebreak
|
||||||
* #6448: autodoc: crashed when autodocumenting classes with ``__slots__ = None``
|
* #6448: autodoc: crashed when autodocumenting classes with ``__slots__ = None``
|
||||||
* #6452: autosummary: crashed when generating document of properties
|
* #6452: autosummary: crashed when generating document of properties
|
||||||
|
* #6451: autodoc: generates docs for "optional import"ed modules as variables
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
|||||||
@@ -357,6 +357,17 @@ class VariableCommentPicker(ast.NodeVisitor):
|
|||||||
except TypeError:
|
except TypeError:
|
||||||
pass # this assignment is not new definition!
|
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):
|
def visit_ClassDef(self, node):
|
||||||
# type: (ast.ClassDef) -> None
|
# type: (ast.ClassDef) -> None
|
||||||
"""Handles ClassDef node and set context."""
|
"""Handles ClassDef node and set context."""
|
||||||
|
|||||||
@@ -149,6 +149,21 @@ def test_complex_assignment_py3():
|
|||||||
assert parser.definitions == {}
|
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():
|
def test_obj_assignment():
|
||||||
source = ('obj = SomeObject() #: some object\n'
|
source = ('obj = SomeObject() #: some object\n'
|
||||||
'obj.attr = 1 #: attr1\n'
|
'obj.attr = 1 #: attr1\n'
|
||||||
|
|||||||
Reference in New Issue
Block a user