From 1c0aa06c7de2d11f7b11b0eed1d5d2e86a74b520 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 10 Jul 2016 17:50:46 +0200 Subject: [PATCH] PEP 3132 unpacking should not raise an error (it may yield wrong results though at the moment), fixes #707. --- CHANGELOG.rst | 3 ++- jedi/evaluate/iterable.py | 3 +++ jedi/parser/tree.py | 2 +- test/completion/arrays.py | 27 +++++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7e673b32..6adf8d72 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,7 +6,8 @@ Changelog 0.10.0 (2016-06-) +++++++++++++++++ -- Basic type inference for ``yield from`` and ``star unpacking``. +- Actual semantic completions for the complete Python syntax. +- Basic type inference for ``yield from`` PEP 380. - PEP 484 support (most of the important features of it). Thanks Claude! (@reinhrst) - Again a lot of internal changes. diff --git a/jedi/evaluate/iterable.py b/jedi/evaluate/iterable.py index 3ee4f529..9986c05e 100644 --- a/jedi/evaluate/iterable.py +++ b/jedi/evaluate/iterable.py @@ -533,6 +533,9 @@ def unpack_tuple_to_dict(evaluator, types, exprlist): # This is something that is not yet supported, would also be difficult # to write into a dict. return {} + elif exprlist.type == 'star_expr': # `a, *b, c = x` type unpackings + # Currently we're not supporting them. + return {} raise NotImplementedError diff --git a/jedi/parser/tree.py b/jedi/parser/tree.py index 04677601..eb746b4d 100644 --- a/jedi/parser/tree.py +++ b/jedi/parser/tree.py @@ -1487,7 +1487,7 @@ def _defined_names(current): if is_node(current, 'testlist_star_expr', 'testlist_comp', 'exprlist'): for child in current.children[::2]: names += _defined_names(child) - elif is_node(current, 'atom'): + elif is_node(current, 'atom', 'star_expr'): names += _defined_names(current.children[1]) elif is_node(current, 'power', 'atom_expr'): if current.children[-2] != '**': # Just if there's no operation diff --git a/test/completion/arrays.py b/test/completion/arrays.py index c2aba71e..b6a565e2 100644 --- a/test/completion/arrays.py +++ b/test/completion/arrays.py @@ -401,3 +401,30 @@ def test_func(): pass #? str() x + + +# ----------------- +# PEP 3132 Extended Iterable Unpacking (star unpacking) +# ----------------- + +a, *b, c = [1, 'b', list, dict] +#? int() +a +#? str() +b +#? list +c + +# Not valid syntax +a, *b, *c = [1, 'd', list] +#? int() +a +#? str() +b +#? list +c + +lc = [x for a, *x in [(1, '', 1.0)]] + +#? +lc[0][0]