1
0
forked from VimPlug/jedi

typehints for variables in comments

This commit is contained in:
Claude
2016-02-15 16:02:59 +01:00
parent daeee4ba0c
commit a658f7940c
4 changed files with 91 additions and 49 deletions
+3 -15
View File
@@ -140,27 +140,15 @@ def get_types_for_typing_module(evaluator, typ, node):
def find_type_from_comment_hint(evaluator, stmt):
try:
stmtpos = stmt.parent.children.index(stmt)
except ValueError:
return []
try:
next_sibling = stmt.parent.children[stmtpos + 1]
except IndexError:
return []
if not isinstance(next_sibling, tree.Whitespace):
return []
comment = next_sibling.get_pre_comment()
comment = stmt.get_following_comment_same_line()
if comment is None:
return []
match = re.match(r"\s*type:\s*([^#]*)", comment)
match = re.match(r"^#\s*type:\s*([^#]*)", comment)
if not match:
return []
start_pos = (next_sibling.start_pos[0],
next_sibling.start_pos[1] - len(comment))
annotation = tree.String(
tree.zero_position_modifier,
repr(str(match.group(1).strip())),
start_pos)
stmt.start_pos)
annotation.parent = stmt.parent
return _evaluate_for_annotation(evaluator, annotation)