From 7e4504efbd9c04e0f9d3e013ef108d49a4904981 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 16 Jul 2017 20:07:49 +0200 Subject: [PATCH] Fix ellipsis issues of python2. --- jedi/evaluate/__init__.py | 4 +++- jedi/evaluate/iterable.py | 8 ++++++-- test/test_parso_integration/test_basic.py | 11 ++++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index f0ae92cd..0c378484 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -310,7 +310,9 @@ class Evaluator(object): self.eval_element(context, element.children[-1])) elif typ == 'operator': # Must be an ellipsis, other operators are not evaluated. - assert element.value == '...' + # In Python 2 ellipsis is coded as three single dot tokens, not + # as one token 3 dot token. + assert element.value in ('.', '...') types = set([compiled.create(self, Ellipsis)]) elif typ == 'dotted_name': types = self.eval_atom(context, element.children[0]) diff --git a/jedi/evaluate/iterable.py b/jedi/evaluate/iterable.py index f7ea897d..5d8204f9 100644 --- a/jedi/evaluate/iterable.py +++ b/jedi/evaluate/iterable.py @@ -662,7 +662,7 @@ def py__getitem__(evaluator, context, types, trailer): if isinstance(index, (compiled.CompiledObject, Slice)): index = index.obj - if type(index) not in (float, int, str, unicode, slice): + if type(index) not in (float, int, str, unicode, slice, type(Ellipsis)): # If the index is not clearly defined, we have to get all the # possiblities. for typ in list(types): @@ -869,7 +869,11 @@ def create_index_types(evaluator, context, index): if index == ':': # Like array[:] return set([Slice(context, None, None, None)]) - elif index.type == 'subscript': # subscript is a slice operation. + + elif index.type == 'subscript' and not index.children[0] == '.': + # subscript basically implies a slice operation, except for Python 2's + # Ellipsis. + print(index.children) # Like array[:3] result = [] for el in index.children: diff --git a/test/test_parso_integration/test_basic.py b/test/test_parso_integration/test_basic.py index 13051a42..4eebaa81 100644 --- a/test/test_parso_integration/test_basic.py +++ b/test/test_parso_integration/test_basic.py @@ -82,6 +82,15 @@ def test_add_to_end(): def test_tokenizer_with_string_literal_backslash(): - import jedi c = jedi.Script("statement = u'foo\\\n'; statement").goto_definitions() assert c[0]._name._context.obj == 'foo' + + +def test_ellipsis(): + def_, = jedi.Script(dedent("""\ + class Foo(): + def __getitem__(self, index): + return index + Foo()[...]""")).goto_definitions() + + assert def_.name == 'ellipsis'