forked from VimPlug/jedi
add support for 'with-assignment' hints
This commit is contained in:
@@ -308,6 +308,10 @@ def _name_to_types(evaluator, name, scope):
|
|||||||
types = pep0484.find_type_from_comment_hint_for(evaluator, typ, name)
|
types = pep0484.find_type_from_comment_hint_for(evaluator, typ, name)
|
||||||
if types:
|
if types:
|
||||||
return types
|
return types
|
||||||
|
if typ.isinstance(tree.WithStmt):
|
||||||
|
types = pep0484.find_type_from_comment_hint_with(evaluator, typ, name)
|
||||||
|
if types:
|
||||||
|
return types
|
||||||
if typ.isinstance(tree.ForStmt, tree.CompFor):
|
if typ.isinstance(tree.ForStmt, tree.CompFor):
|
||||||
container_types = evaluator.eval_element(typ.children[3])
|
container_types = evaluator.eval_element(typ.children[3])
|
||||||
for_types = iterable.py__iter__types(evaluator, container_types, typ.children[3])
|
for_types = iterable.py__iter__types(evaluator, container_types, typ.children[3])
|
||||||
|
|||||||
@@ -154,6 +154,13 @@ def find_type_from_comment_hint_for(evaluator, node, name):
|
|||||||
_find_type_from_comment_hint(evaluator, node, node.children[1], name)
|
_find_type_from_comment_hint(evaluator, node, node.children[1], name)
|
||||||
|
|
||||||
|
|
||||||
|
def find_type_from_comment_hint_with(evaluator, node, name):
|
||||||
|
assert len(node.children[1].children) == 3, \
|
||||||
|
"Can only be here when children[1] is 'foo() as f'"
|
||||||
|
return _find_type_from_comment_hint(
|
||||||
|
evaluator, node, node.children[1].children[2], name)
|
||||||
|
|
||||||
|
|
||||||
def find_type_from_comment_hint_assign(evaluator, node, name):
|
def find_type_from_comment_hint_assign(evaluator, node, name):
|
||||||
return \
|
return \
|
||||||
_find_type_from_comment_hint(evaluator, node, node.children[0], name)
|
_find_type_from_comment_hint(evaluator, node, node.children[0], name)
|
||||||
|
|||||||
@@ -526,6 +526,8 @@ class BaseNode(Base):
|
|||||||
try:
|
try:
|
||||||
if self.isinstance(ForStmt):
|
if self.isinstance(ForStmt):
|
||||||
whitespace = self.children[5].first_leaf().prefix
|
whitespace = self.children[5].first_leaf().prefix
|
||||||
|
elif self.isinstance(WithStmt):
|
||||||
|
whitespace = self.children[3].first_leaf().prefix
|
||||||
else:
|
else:
|
||||||
whitespace = self.last_leaf().get_next().prefix
|
whitespace = self.last_leaf().get_next().prefix
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|||||||
@@ -77,3 +77,10 @@ for bar, baz in foo(): # type: int, float
|
|||||||
bar
|
bar
|
||||||
#? float()
|
#? float()
|
||||||
baz
|
baz
|
||||||
|
|
||||||
|
with foo(): # type: int
|
||||||
|
...
|
||||||
|
|
||||||
|
with foo() as f: # type: str
|
||||||
|
#? str()
|
||||||
|
f
|
||||||
|
|||||||
Reference in New Issue
Block a user