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
|
||||
|
||||
TODO nonlocal statement
|
||||
TODO doc
|
||||
TODO list comprehensions, priority?
|
||||
TODO annotations ? how ? type evaluation and return?
|
||||
TODO evaluate asserts (type safety)
|
||||
TODO generators
|
||||
|
||||
python 3 stuff:
|
||||
TODO class decorators
|
||||
TODO annotations ? how ? type evaluation and return?
|
||||
TODO nonlocal statement
|
||||
"""
|
||||
from _compatibility import next
|
||||
|
||||
@@ -446,9 +449,17 @@ class Array(object):
|
||||
def get_index_types(self, index=None):
|
||||
values = self._array.values
|
||||
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,
|
||||
# otherwise it just ignores the index (e.g. [1+1])
|
||||
try:
|
||||
# multiple elements in the array
|
||||
i = index.get_only_subelement().name
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
return self.get_exact_index_types(i)
|
||||
except (IndexError, KeyError):
|
||||
@@ -841,6 +852,7 @@ def follow_path(path, scope, position=None):
|
||||
if isinstance(current, parsing.Array):
|
||||
# this must be an execution, either () or []
|
||||
if current.type == parsing.Array.LIST:
|
||||
print 'cur', current, scope
|
||||
result = scope.get_index_types(current)
|
||||
elif current.type not in [parsing.Array.DICT]:
|
||||
# scope must be a class or func - make an instance or execution
|
||||
|
||||
@@ -658,6 +658,9 @@ class Statement(Simple):
|
||||
if is_call_or_close():
|
||||
result = result.parent
|
||||
close_brackets = False
|
||||
if result.type == Array.LIST: # [:] lookups
|
||||
result.add_to_current_field(tok)
|
||||
else:
|
||||
result.add_dictionary_key()
|
||||
elif tok == '.':
|
||||
if close_brackets and result.parent != top:
|
||||
|
||||
@@ -12,7 +12,21 @@ a = list()
|
||||
[a][0].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