mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
: lookups work now with arrays
This commit is contained in:
16
evaluate.py
16
evaluate.py
@@ -4,12 +4,15 @@ follow_statement -> follow_call -> follow_paths -> follow_path
|
|||||||
|
|
||||||
`get_names_for_scope` and `get_scopes_for_name` are search functions
|
`get_names_for_scope` and `get_scopes_for_name` are search functions
|
||||||
|
|
||||||
TODO nonlocal statement
|
|
||||||
TODO doc
|
TODO doc
|
||||||
TODO list comprehensions, priority?
|
TODO list comprehensions, priority?
|
||||||
TODO annotations ? how ? type evaluation and return?
|
|
||||||
TODO evaluate asserts (type safety)
|
TODO evaluate asserts (type safety)
|
||||||
TODO generators
|
TODO generators
|
||||||
|
|
||||||
|
python 3 stuff:
|
||||||
|
TODO class decorators
|
||||||
|
TODO annotations ? how ? type evaluation and return?
|
||||||
|
TODO nonlocal statement
|
||||||
"""
|
"""
|
||||||
from _compatibility import next
|
from _compatibility import next
|
||||||
|
|
||||||
@@ -446,9 +449,17 @@ class Array(object):
|
|||||||
def get_index_types(self, index=None):
|
def get_index_types(self, index=None):
|
||||||
values = self._array.values
|
values = self._array.values
|
||||||
if index is not None:
|
if index is not None:
|
||||||
|
if [x for x in index if ':' in x]:
|
||||||
|
return [self]
|
||||||
|
else:
|
||||||
# This is indexing only one element, with a fixed index number,
|
# This is indexing only one element, with a fixed index number,
|
||||||
# otherwise it just ignores the index (e.g. [1+1])
|
# otherwise it just ignores the index (e.g. [1+1])
|
||||||
|
try:
|
||||||
|
# multiple elements in the array
|
||||||
i = index.get_only_subelement().name
|
i = index.get_only_subelement().name
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
return self.get_exact_index_types(i)
|
return self.get_exact_index_types(i)
|
||||||
except (IndexError, KeyError):
|
except (IndexError, KeyError):
|
||||||
@@ -841,6 +852,7 @@ def follow_path(path, scope, position=None):
|
|||||||
if isinstance(current, parsing.Array):
|
if isinstance(current, parsing.Array):
|
||||||
# this must be an execution, either () or []
|
# this must be an execution, either () or []
|
||||||
if current.type == parsing.Array.LIST:
|
if current.type == parsing.Array.LIST:
|
||||||
|
print 'cur', current, scope
|
||||||
result = scope.get_index_types(current)
|
result = scope.get_index_types(current)
|
||||||
elif current.type not in [parsing.Array.DICT]:
|
elif current.type not in [parsing.Array.DICT]:
|
||||||
# scope must be a class or func - make an instance or execution
|
# scope must be a class or func - make an instance or execution
|
||||||
|
|||||||
@@ -658,6 +658,9 @@ class Statement(Simple):
|
|||||||
if is_call_or_close():
|
if is_call_or_close():
|
||||||
result = result.parent
|
result = result.parent
|
||||||
close_brackets = False
|
close_brackets = False
|
||||||
|
if result.type == Array.LIST: # [:] lookups
|
||||||
|
result.add_to_current_field(tok)
|
||||||
|
else:
|
||||||
result.add_dictionary_key()
|
result.add_dictionary_key()
|
||||||
elif tok == '.':
|
elif tok == '.':
|
||||||
if close_brackets and result.parent != top:
|
if close_brackets and result.parent != top:
|
||||||
|
|||||||
@@ -12,7 +12,21 @@ a = list()
|
|||||||
[a][0].append
|
[a][0].append
|
||||||
|
|
||||||
#? ['append']
|
#? ['append']
|
||||||
[[a]][0][100].append
|
[[a,a,a]][2][100].append
|
||||||
|
|
||||||
|
c = [[a,""]]
|
||||||
|
#? []
|
||||||
|
c[0][1].append
|
||||||
|
#? ['upper']
|
||||||
|
c[0][1].upper
|
||||||
|
|
||||||
|
b = [6,7]
|
||||||
|
|
||||||
|
#? ['real']
|
||||||
|
b[8-7].real
|
||||||
|
|
||||||
|
#? ['append']
|
||||||
|
b[8:].append
|
||||||
|
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user