forked from VimPlug/jedi
Fix wrong types for iterate, fixes #1524
This commit is contained in:
@@ -140,7 +140,6 @@ class ComprehensionMixin(object):
|
|||||||
input_node = comp_for.children[3]
|
input_node = comp_for.children[3]
|
||||||
parent_context = parent_context or self._defining_context
|
parent_context = parent_context or self._defining_context
|
||||||
input_types = parent_context.infer_node(input_node)
|
input_types = parent_context.infer_node(input_node)
|
||||||
# TODO: simulate await if self.is_async
|
|
||||||
|
|
||||||
cn = ContextualizedNode(parent_context, input_node)
|
cn = ContextualizedNode(parent_context, input_node)
|
||||||
iterated = input_types.iterate(cn, is_async=is_async)
|
iterated = input_types.iterate(cn, is_async=is_async)
|
||||||
@@ -578,33 +577,31 @@ class MergedArray(Sequence):
|
|||||||
return ValueSet.from_sets(lazy_value.infer() for lazy_value in self.py__iter__())
|
return ValueSet.from_sets(lazy_value.infer() for lazy_value in self.py__iter__())
|
||||||
|
|
||||||
|
|
||||||
def unpack_tuple_to_dict(value, types, exprlist):
|
def unpack_tuple_to_dict(context, types, exprlist):
|
||||||
"""
|
"""
|
||||||
Unpacking tuple assignments in for statements and expr_stmts.
|
Unpacking tuple assignments in for statements and expr_stmts.
|
||||||
"""
|
"""
|
||||||
if exprlist.type == 'name':
|
if exprlist.type == 'name':
|
||||||
return {exprlist.value: types}
|
return {exprlist.value: types}
|
||||||
elif exprlist.type == 'atom' and exprlist.children[0] in ('(', '['):
|
elif exprlist.type == 'atom' and exprlist.children[0] in ('(', '['):
|
||||||
return unpack_tuple_to_dict(value, types, exprlist.children[1])
|
return unpack_tuple_to_dict(context, types, exprlist.children[1])
|
||||||
elif exprlist.type in ('testlist', 'testlist_comp', 'exprlist',
|
elif exprlist.type in ('testlist', 'testlist_comp', 'exprlist',
|
||||||
'testlist_star_expr'):
|
'testlist_star_expr'):
|
||||||
dct = {}
|
dct = {}
|
||||||
parts = iter(exprlist.children[::2])
|
parts = iter(exprlist.children[::2])
|
||||||
n = 0
|
n = 0
|
||||||
for lazy_value in types.iterate(exprlist):
|
for lazy_value in types.iterate(ContextualizedNode(context, exprlist)):
|
||||||
n += 1
|
n += 1
|
||||||
try:
|
try:
|
||||||
part = next(parts)
|
part = next(parts)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
# TODO this value is probably not right.
|
analysis.add(context, 'value-error-too-many-values', part,
|
||||||
analysis.add(value, 'value-error-too-many-values', part,
|
|
||||||
message="ValueError: too many values to unpack (expected %s)" % n)
|
message="ValueError: too many values to unpack (expected %s)" % n)
|
||||||
else:
|
else:
|
||||||
dct.update(unpack_tuple_to_dict(value, lazy_value.infer(), part))
|
dct.update(unpack_tuple_to_dict(context, lazy_value.infer(), part))
|
||||||
has_parts = next(parts, None)
|
has_parts = next(parts, None)
|
||||||
if types and has_parts is not None:
|
if types and has_parts is not None:
|
||||||
# TODO this value is probably not right.
|
analysis.add(context, 'value-error-too-few-values', has_parts,
|
||||||
analysis.add(value, 'value-error-too-few-values', has_parts,
|
|
||||||
message="ValueError: need more than %s values to unpack" % n)
|
message="ValueError: need more than %s values to unpack" % n)
|
||||||
return dct
|
return dct
|
||||||
elif exprlist.type == 'power' or exprlist.type == 'atom_expr':
|
elif exprlist.type == 'power' or exprlist.type == 'atom_expr':
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ b[0]
|
|||||||
#? str()
|
#? str()
|
||||||
[x for x in 'chr'][0]
|
[x for x in 'chr'][0]
|
||||||
|
|
||||||
# jedi issue #26
|
# From GitHub #26
|
||||||
#? list()
|
#? list()
|
||||||
a = [[int(v) for v in line.strip().split() if v] for line in ["123", str(), "123"] if line]
|
a = [[int(v) for v in line.strip().split() if v] for line in ["123", str(), "123"] if line]
|
||||||
#? list()
|
#? list()
|
||||||
@@ -99,6 +99,10 @@ a[0]
|
|||||||
#? int()
|
#? int()
|
||||||
a[0][0]
|
a[0][0]
|
||||||
|
|
||||||
|
# From GitHub #1524
|
||||||
|
#?
|
||||||
|
[nothing for nothing, _ in [1]][0]
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# generator comprehensions
|
# generator comprehensions
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user