1
0
forked from VimPlug/jedi

Fix ellipsis issues of python2.

This commit is contained in:
Dave Halter
2017-07-16 20:07:49 +02:00
parent 54490be1b2
commit 7e4504efbd
3 changed files with 19 additions and 4 deletions

View File

@@ -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])

View File

@@ -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:

View File

@@ -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'