1
0
forked from VimPlug/jedi

Add attribute docstrings (PEP 257) support

This commit is contained in:
Takafumi Arakaki
2013-02-24 19:26:56 +01:00
parent 19b41c1cb4
commit 740f27c8b8

View File

@@ -395,6 +395,22 @@ class Parser(object):
self._check_user_stmt(stmt)
# Attribute docstring (PEP 257) support
try:
# If string literal is being parsed
first_tok = stmt.token_list[0]
if (not stmt.set_vars and
not stmt.used_vars and
len(stmt.token_list) == 1 and
first_tok[0] == tokenize.STRING):
# ... and the last statement was assignment
last_stmt = self.scope.statements[-1]
if last_stmt.assignment_details[0][1] == '=':
# ... then set it as a docstring
last_stmt.add_docstr(first_tok[1])
except (IndexError, AttributeError):
pass
if tok in always_break + not_first_break:
self._gen.push_last_back()
return stmt, tok