summaryrefslogtreecommitdiff
path: root/sphinx/pycode/parser.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-02-01 13:38:34 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-02-03 01:19:05 +0900
commit92cb828f14afb61645ea807f456d9ba9f0f8d0e0 (patch)
tree272d27c61e4001c3c005070d10998165085a7eb6 /sphinx/pycode/parser.py
parent20126433d6598a53eee0067bfb0ae641128b864f (diff)
downloadsphinx-git-92cb828f14afb61645ea807f456d9ba9f0f8d0e0.tar.gz
autodoc: Support type_comment styled type annotation for variables
Diffstat (limited to 'sphinx/pycode/parser.py')
-rw-r--r--sphinx/pycode/parser.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py
index 4ec1a844d..1f803e950 100644
--- a/sphinx/pycode/parser.py
+++ b/sphinx/pycode/parser.py
@@ -311,10 +311,12 @@ class VariableCommentPicker(ast.NodeVisitor):
return # this assignment is not new definition!
# record annotation
- annotation = getattr(node, 'annotation', None)
- if annotation:
+ if hasattr(node, 'annotation') and node.annotation: # type: ignore
for varname in varnames:
- self.add_variable_annotation(varname, annotation)
+ self.add_variable_annotation(varname, node.annotation) # type: ignore
+ elif hasattr(node, 'type_comment') and node.type_comment:
+ for varname in varnames:
+ self.add_variable_annotation(varname, node.type_comment) # type: ignore
# check comments after assignment
parser = AfterCommentParser([current_line[node.col_offset:]] +