summaryrefslogtreecommitdiff
path: root/sphinx/pycode/parser.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-07-13 22:02:49 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-07-13 22:02:49 +0900
commit8c924f1b3da25b778baedb30cbeca43f5cef6d71 (patch)
tree90db9f46fa3543d7b2bf6e1cb5f669e2283a51d7 /sphinx/pycode/parser.py
parent0bc530f1b7b3303e0f53e42010b629d67e79b835 (diff)
downloadsphinx-git-8c924f1b3da25b778baedb30cbeca43f5cef6d71.tar.gz
Fix autodoc: autodoc_member_order_does not refer order of imports (refs: #6574)
Diffstat (limited to 'sphinx/pycode/parser.py')
-rw-r--r--sphinx/pycode/parser.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py
index cbcb3b17d..534f2310a 100644
--- a/sphinx/pycode/parser.py
+++ b/sphinx/pycode/parser.py
@@ -270,6 +270,22 @@ class VariableCommentPicker(ast.NodeVisitor):
super().visit(node)
self.previous = node
+ def visit_Import(self, node: ast.Import) -> None:
+ """Handles Import node and record it to definition orders."""
+ for name in node.names:
+ if name.asname:
+ self.add_entry(name.asname)
+ else:
+ self.add_entry(name.name)
+
+ def visit_ImportFrom(self, node: ast.Import) -> None:
+ """Handles Import node and record it to definition orders."""
+ for name in node.names:
+ if name.asname:
+ self.add_entry(name.asname)
+ else:
+ self.add_entry(name.name)
+
def visit_Assign(self, node: ast.Assign) -> None:
"""Handles Assign node and pick up a variable comment."""
try: