forked from VimPlug/jedi
Fix ellipsis issues of python2.
This commit is contained in:
@@ -310,7 +310,9 @@ class Evaluator(object):
|
|||||||
self.eval_element(context, element.children[-1]))
|
self.eval_element(context, element.children[-1]))
|
||||||
elif typ == 'operator':
|
elif typ == 'operator':
|
||||||
# Must be an ellipsis, other operators are not evaluated.
|
# 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)])
|
types = set([compiled.create(self, Ellipsis)])
|
||||||
elif typ == 'dotted_name':
|
elif typ == 'dotted_name':
|
||||||
types = self.eval_atom(context, element.children[0])
|
types = self.eval_atom(context, element.children[0])
|
||||||
|
|||||||
@@ -662,7 +662,7 @@ def py__getitem__(evaluator, context, types, trailer):
|
|||||||
if isinstance(index, (compiled.CompiledObject, Slice)):
|
if isinstance(index, (compiled.CompiledObject, Slice)):
|
||||||
index = index.obj
|
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
|
# If the index is not clearly defined, we have to get all the
|
||||||
# possiblities.
|
# possiblities.
|
||||||
for typ in list(types):
|
for typ in list(types):
|
||||||
@@ -869,7 +869,11 @@ def create_index_types(evaluator, context, index):
|
|||||||
if index == ':':
|
if index == ':':
|
||||||
# Like array[:]
|
# Like array[:]
|
||||||
return set([Slice(context, None, None, None)])
|
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]
|
# Like array[:3]
|
||||||
result = []
|
result = []
|
||||||
for el in index.children:
|
for el in index.children:
|
||||||
|
|||||||
@@ -82,6 +82,15 @@ def test_add_to_end():
|
|||||||
|
|
||||||
|
|
||||||
def test_tokenizer_with_string_literal_backslash():
|
def test_tokenizer_with_string_literal_backslash():
|
||||||
import jedi
|
|
||||||
c = jedi.Script("statement = u'foo\\\n'; statement").goto_definitions()
|
c = jedi.Script("statement = u'foo\\\n'; statement").goto_definitions()
|
||||||
assert c[0]._name._context.obj == 'foo'
|
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'
|
||||||
|
|||||||
Reference in New Issue
Block a user