mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
also remove crashes with pep 448 unpacking of lists and sets
This commit is contained in:
@@ -346,7 +346,9 @@ class SequenceLiteralContext(Sequence):
|
|||||||
return [] # Direct closing bracket, doesn't contain items.
|
return [] # Direct closing bracket, doesn't contain items.
|
||||||
|
|
||||||
if array_node.type == 'testlist_comp':
|
if array_node.type == 'testlist_comp':
|
||||||
return array_node.children[::2]
|
# filter out (for now) pep 448 single-star unpacking
|
||||||
|
return [value for value in array_node.children[::2]
|
||||||
|
if value.type != "star_expr"]
|
||||||
elif array_node.type == 'dictorsetmaker':
|
elif array_node.type == 'dictorsetmaker':
|
||||||
kv = []
|
kv = []
|
||||||
iterator = iter(array_node.children)
|
iterator = iter(array_node.children)
|
||||||
@@ -359,12 +361,22 @@ class SequenceLiteralContext(Sequence):
|
|||||||
else:
|
else:
|
||||||
op = next(iterator, None)
|
op = next(iterator, None)
|
||||||
if op is None or op == ',':
|
if op is None or op == ',':
|
||||||
|
if key.type == "star_expr":
|
||||||
|
# pep 448 single-star unpacking
|
||||||
|
# for now ignoring values imported by *
|
||||||
|
pass
|
||||||
|
else:
|
||||||
kv.append(key) # A set.
|
kv.append(key) # A set.
|
||||||
else:
|
else:
|
||||||
assert op == ':' # A dict.
|
assert op == ':' # A dict.
|
||||||
kv.append((key, next(iterator)))
|
kv.append((key, next(iterator)))
|
||||||
next(iterator, None) # Possible comma.
|
next(iterator, None) # Possible comma.
|
||||||
return kv
|
return kv
|
||||||
|
else:
|
||||||
|
if array_node.type == "star_expr":
|
||||||
|
# pep 448 single-star unpacking
|
||||||
|
# for now ignoring values imported by *
|
||||||
|
return []
|
||||||
else:
|
else:
|
||||||
return [array_node]
|
return [array_node]
|
||||||
|
|
||||||
|
|||||||
@@ -147,5 +147,30 @@ d = {'a': 3}
|
|||||||
|
|
||||||
# Should resolve to int() but jedi is not smart enough yet
|
# Should resolve to int() but jedi is not smart enough yet
|
||||||
# Here to make sure it doesn't result in crash though
|
# Here to make sure it doesn't result in crash though
|
||||||
#? str()
|
#?
|
||||||
{**d, "b": "b"}["a"]
|
{**d}["a"]
|
||||||
|
|
||||||
|
s = {1, 2, 3}
|
||||||
|
|
||||||
|
#? set()
|
||||||
|
{*s}
|
||||||
|
|
||||||
|
#? set()
|
||||||
|
{*s, 4, *s}
|
||||||
|
|
||||||
|
s = {1, 2, 3}
|
||||||
|
# Should resolve to int() but jedi is not smart enough yet
|
||||||
|
# Here to make sure it doesn't result in crash though
|
||||||
|
#?
|
||||||
|
{*s}.pop()
|
||||||
|
|
||||||
|
#? int()
|
||||||
|
{*s, 4}.pop()
|
||||||
|
|
||||||
|
# Should resolve to int() but jedi is not smart enough yet
|
||||||
|
# Here to make sure it doesn't result in crash though
|
||||||
|
#?
|
||||||
|
[*s][0]
|
||||||
|
|
||||||
|
#? int()
|
||||||
|
[*s, 4][0]
|
||||||
|
|||||||
Reference in New Issue
Block a user