From 6bc79b493323e5e1eff03daa109fd4dc2d6f7682 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 22 Sep 2018 22:18:17 +0200 Subject: [PATCH] Fixed crash (and now recognises correctly) {**d, "b": "b"}["b"] --- jedi/evaluate/context/iterable.py | 18 ++++++++++++------ test/completion/types.py | 10 ++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/jedi/evaluate/context/iterable.py b/jedi/evaluate/context/iterable.py index 31011e36..45b3f435 100644 --- a/jedi/evaluate/context/iterable.py +++ b/jedi/evaluate/context/iterable.py @@ -351,13 +351,19 @@ class SequenceLiteralContext(Sequence): kv = [] iterator = iter(array_node.children) for key in iterator: - op = next(iterator, None) - if op is None or op == ',': - kv.append(key) # A set. - else: - assert op == ':' # A dict. - kv.append((key, next(iterator))) + if key == "**": + # dict with pep 448 double-star unpacking + # for now ignoring the values imported by ** + next(iterator) next(iterator, None) # Possible comma. + else: + op = next(iterator, None) + if op is None or op == ',': + 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] diff --git a/test/completion/types.py b/test/completion/types.py index a6aca08b..a01d2425 100644 --- a/test/completion/types.py +++ b/test/completion/types.py @@ -137,5 +137,15 @@ set_t2.c # ----------------- # python >= 3.5 +d = {'a': 3} + #? dict() {**d} + +#? str() +{**d, "b": "b"}["b"] + +# 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"]