diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2017-10-19 00:10:46 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2017-10-19 00:10:46 +0900 |
commit | 1dfe978fcb60c4ba4c30914f5c2f4916123d91b3 (patch) | |
tree | 29b86ee7756b7b987dcf7cf8b3b039de2d0f78f2 /sphinx/pycode/parser.py | |
parent | 4fdcae05843cfc1be155620ade9dff10ab3e9853 (diff) | |
download | sphinx-git-1dfe978fcb60c4ba4c30914f5c2f4916123d91b3.tar.gz |
Support more complex starred asssignment case
Diffstat (limited to 'sphinx/pycode/parser.py')
-rw-r--r-- | sphinx/pycode/parser.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py index 1191551c4..a22891fd7 100644 --- a/sphinx/pycode/parser.py +++ b/sphinx/pycode/parser.py @@ -52,8 +52,13 @@ def get_lvar_names(node, self=None): else: raise TypeError('The assignment %r is not instance variable' % node) elif node_name in ('Tuple', 'List'): - members = [get_lvar_names(elt) for elt in node.elts] # type: ignore - return sum(members, []) + members = [] + for elt in node.elts: + try: + members.extend(get_lvar_names(elt, self)) + except TypeError: + pass + return members elif node_name == 'Attribute': if node.value.__class__.__name__ == 'Name' and self and node.value.id == self_id: # type: ignore # NOQA # instance variable @@ -63,7 +68,7 @@ def get_lvar_names(node, self=None): elif node_name == 'str': return [node] # type: ignore elif node_name == 'Starred': - return [node.value.id] # type: ignore + return get_lvar_names(node.value, self) # type: ignore else: raise NotImplementedError('Unexpected node name %r' % node_name) @@ -281,7 +286,7 @@ class VariableCommentPicker(ast.NodeVisitor): try: varnames = sum([get_lvar_names(t, self=self.get_self()) for t in node.targets], []) # type: ignore # NOQA current_line = self.get_line(node.lineno) - except TypeError: + except TypeError as exc: return # this assignment is not new definition! # check comments after assignment |