From a2b984ce24f6ac730d67d56135680429f77b96d3 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 22 Sep 2018 23:29:13 +0200 Subject: [PATCH] also remove crashes with pep 448 unpacking of lists and sets --- jedi/evaluate/context/iterable.py | 18 +++++++++++++++--- test/completion/types.py | 29 +++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/jedi/evaluate/context/iterable.py b/jedi/evaluate/context/iterable.py index 45b3f435..c69498e7 100644 --- a/jedi/evaluate/context/iterable.py +++ b/jedi/evaluate/context/iterable.py @@ -346,7 +346,9 @@ class SequenceLiteralContext(Sequence): return [] # Direct closing bracket, doesn't contain items. 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': kv = [] iterator = iter(array_node.children) @@ -359,14 +361,24 @@ class SequenceLiteralContext(Sequence): else: op = next(iterator, None) if op is None or op == ',': - kv.append(key) # A set. + if key.type == "star_expr": + # pep 448 single-star unpacking + # for now ignoring values imported by * + pass + else: + kv.append(key) # A set. else: assert op == ':' # A dict. kv.append((key, next(iterator))) next(iterator, None) # Possible comma. return kv else: - return [array_node] + if array_node.type == "star_expr": + # pep 448 single-star unpacking + # for now ignoring values imported by * + return [] + else: + return [array_node] def exact_key_items(self): """ diff --git a/test/completion/types.py b/test/completion/types.py index a01d2425..f0c4c838 100644 --- a/test/completion/types.py +++ b/test/completion/types.py @@ -147,5 +147,30 @@ d = {'a': 3} # Should resolve to int() but jedi is not smart enough yet # 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]