mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Fix star_expr unpacking issues. For now star_expr is not supported
This commit is contained in:
@@ -247,18 +247,30 @@ class ContextualizedName(ContextualizedNode):
|
|||||||
x, (y, z) = 2, ''
|
x, (y, z) = 2, ''
|
||||||
|
|
||||||
would result in ``[(1, xyz_node), (0, yz_node)]``.
|
would result in ``[(1, xyz_node), (0, yz_node)]``.
|
||||||
|
|
||||||
|
When searching for b in the case ``a, *b, c = [...]`` it will return::
|
||||||
|
|
||||||
|
[(slice(1, -1), abc_node)]
|
||||||
"""
|
"""
|
||||||
indexes = []
|
indexes = []
|
||||||
|
is_star_expr = False
|
||||||
node = self.node.parent
|
node = self.node.parent
|
||||||
compare = self.node
|
compare = self.node
|
||||||
while node is not None:
|
while node is not None:
|
||||||
if node.type in ('testlist', 'testlist_comp', 'testlist_star_expr', 'exprlist'):
|
if node.type in ('testlist', 'testlist_comp', 'testlist_star_expr', 'exprlist'):
|
||||||
for i, child in enumerate(node.children):
|
for i, child in enumerate(node.children):
|
||||||
if child == compare:
|
if child == compare:
|
||||||
indexes.insert(0, (int(i / 2), node))
|
index = int(i / 2)
|
||||||
|
if is_star_expr:
|
||||||
|
from_end = int((len(node.children) - i) / 2)
|
||||||
|
index = slice(index, -from_end)
|
||||||
|
indexes.insert(0, (index, node))
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
raise LookupError("Couldn't find the assignment.")
|
raise LookupError("Couldn't find the assignment.")
|
||||||
|
is_star_expr = False
|
||||||
|
elif node.type == 'star_expr':
|
||||||
|
is_star_expr = True
|
||||||
elif isinstance(node, (ExprStmt, CompFor)):
|
elif isinstance(node, (ExprStmt, CompFor)):
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
@@ -636,6 +636,9 @@ def check_tuple_assignments(evaluator, contextualized_name, context_set):
|
|||||||
for index, node in contextualized_name.assignment_indexes():
|
for index, node in contextualized_name.assignment_indexes():
|
||||||
cn = ContextualizedNode(contextualized_name.context, node)
|
cn = ContextualizedNode(contextualized_name.context, node)
|
||||||
iterated = context_set.iterate(cn)
|
iterated = context_set.iterate(cn)
|
||||||
|
if isinstance(index, slice):
|
||||||
|
# For no star unpacking is not possible.
|
||||||
|
return NO_CONTEXTS
|
||||||
for _ in range(index + 1):
|
for _ in range(index + 1):
|
||||||
try:
|
try:
|
||||||
lazy_context = next(iterated)
|
lazy_context = next(iterated)
|
||||||
|
|||||||
@@ -448,7 +448,7 @@ tuple({1})[0]
|
|||||||
a, *b, c = [1, 'b', list, dict]
|
a, *b, c = [1, 'b', list, dict]
|
||||||
#? int()
|
#? int()
|
||||||
a
|
a
|
||||||
#? str()
|
#?
|
||||||
b
|
b
|
||||||
#? list
|
#? list
|
||||||
c
|
c
|
||||||
@@ -457,12 +457,14 @@ c
|
|||||||
a, *b, *c = [1, 'd', list]
|
a, *b, *c = [1, 'd', list]
|
||||||
#? int()
|
#? int()
|
||||||
a
|
a
|
||||||
#? str()
|
#?
|
||||||
b
|
b
|
||||||
#? list
|
#?
|
||||||
c
|
c
|
||||||
|
|
||||||
lc = [x for a, *x in [(1, '', 1.0)]]
|
lc = [x for a, *x in [(1, '', 1.0)]]
|
||||||
|
|
||||||
#?
|
#?
|
||||||
lc[0][0]
|
lc[0][0]
|
||||||
|
#?
|
||||||
|
lc[0][1]
|
||||||
|
|||||||
Reference in New Issue
Block a user