forked from VimPlug/jedi
A first array test passing.
This commit is contained in:
@@ -189,7 +189,7 @@ class Evaluator(object):
|
|||||||
elif isinstance(atom, pr.Literal):
|
elif isinstance(atom, pr.Literal):
|
||||||
return [compiled.create(self, atom.eval())]
|
return [compiled.create(self, atom.eval())]
|
||||||
else:
|
else:
|
||||||
return iterable.Array(self, atom.children[1])
|
return [iterable.Array(self, atom.children[1], pr.Array.LIST)]
|
||||||
|
|
||||||
def eval_trailer(self, types, trailer):
|
def eval_trailer(self, types, trailer):
|
||||||
trailer_op, node = trailer.children[:2]
|
trailer_op, node = trailer.children[:2]
|
||||||
@@ -202,7 +202,7 @@ class Evaluator(object):
|
|||||||
elif trailer_op == '(':
|
elif trailer_op == '(':
|
||||||
new_types += self.execute(typ, node)
|
new_types += self.execute(typ, node)
|
||||||
elif trailer_op == '[':
|
elif trailer_op == '[':
|
||||||
raise NotImplementedError
|
new_types += typ.get_index_types(node)
|
||||||
return new_types
|
return new_types
|
||||||
|
|
||||||
@debug.increase_indent
|
@debug.increase_indent
|
||||||
|
|||||||
@@ -124,9 +124,10 @@ class Array(use_metaclass(CachedMetaClass, IterableWrapper)):
|
|||||||
Used as a mirror to pr.Array, if needed. It defines some getter
|
Used as a mirror to pr.Array, if needed. It defines some getter
|
||||||
methods which are important in this module.
|
methods which are important in this module.
|
||||||
"""
|
"""
|
||||||
def __init__(self, evaluator, array_node):
|
def __init__(self, evaluator, array_node, type):
|
||||||
self._evaluator = evaluator
|
self._evaluator = evaluator
|
||||||
self._array_node = array_node
|
self._array_node = array_node
|
||||||
|
self.type = type
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@@ -136,14 +137,14 @@ class Array(use_metaclass(CachedMetaClass, IterableWrapper)):
|
|||||||
return None # We don't know the length, because of appends.
|
return None # We don't know the length, because of appends.
|
||||||
|
|
||||||
@memoize_default(NO_DEFAULT)
|
@memoize_default(NO_DEFAULT)
|
||||||
def get_index_types(self, index_array=()):
|
def get_index_types(self, index=()):
|
||||||
"""
|
"""
|
||||||
Get the types of a specific index or all, if not given.
|
Get the types of a specific index or all, if not given.
|
||||||
|
|
||||||
:param indexes: The index input types.
|
:param index: A subscriptlist node (or subnode).
|
||||||
"""
|
"""
|
||||||
indexes = create_indexes_or_slices(self._evaluator, index_array)
|
indexes = create_indexes_or_slices(self._evaluator, index)
|
||||||
if [index for index in indexes if isinstance(index, Slice)]:
|
if [i for i in indexes if isinstance(index, Slice)]:
|
||||||
return [self]
|
return [self]
|
||||||
|
|
||||||
lookup_done = False
|
lookup_done = False
|
||||||
@@ -188,8 +189,7 @@ class Array(use_metaclass(CachedMetaClass, IterableWrapper)):
|
|||||||
raise KeyError('No key found in dictionary')
|
raise KeyError('No key found in dictionary')
|
||||||
|
|
||||||
# Can raise an IndexError
|
# Can raise an IndexError
|
||||||
values = [self._array.values[index]]
|
return self._evaluator.eval_element(self._items()[index])
|
||||||
return _follow_values(self._evaluator, values)
|
|
||||||
|
|
||||||
def scope_names_generator(self, position=None):
|
def scope_names_generator(self, position=None):
|
||||||
"""
|
"""
|
||||||
@@ -215,13 +215,13 @@ class Array(use_metaclass(CachedMetaClass, IterableWrapper)):
|
|||||||
raise AttributeError('Strange access on %s: %s.' % (self, name))
|
raise AttributeError('Strange access on %s: %s.' % (self, name))
|
||||||
return getattr(self._array, name)
|
return getattr(self._array, name)
|
||||||
|
|
||||||
def __iter__(self):
|
def _items(self):
|
||||||
if pr.is_node(self._array_node, 'testlist_comp'):
|
if pr.is_node(self._array_node, 'testlist_comp'):
|
||||||
return iter(self._array_node.children[::2])
|
return self._array_node.children[::2]
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def __len__(self):
|
def __iter__(self):
|
||||||
return len(self._array)
|
return iter(self._items())
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<e%s of %s>" % (type(self).__name__, self._array_node)
|
return "<e%s of %s>" % (type(self).__name__, self._array_node)
|
||||||
@@ -490,14 +490,15 @@ class Slice(object):
|
|||||||
return slice(None, None, None)
|
return slice(None, None, None)
|
||||||
|
|
||||||
|
|
||||||
def create_indexes_or_slices(evaluator, index_array):
|
def create_indexes_or_slices(evaluator, index):
|
||||||
if not index_array:
|
return evaluator.eval_element(index)
|
||||||
return ()
|
# TODO delete the rest?
|
||||||
|
|
||||||
|
|
||||||
# Just take the first part of the "array", because this is Python stdlib
|
# Just take the first part of the "array", because this is Python stdlib
|
||||||
# behavior. Numpy et al. perform differently, but Jedi won't understand
|
# behavior. Numpy et al. perform differently, but Jedi won't understand
|
||||||
# that anyway.
|
# that anyway.
|
||||||
expression_list = index_array[0].expression_list()
|
expression_list = index[0].expression_list()
|
||||||
prec = precedence.create_precedence(expression_list)
|
prec = precedence.create_precedence(expression_list)
|
||||||
|
|
||||||
# check for slices
|
# check for slices
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ class Parser(object):
|
|||||||
# and only if the refactor method's write parameter was True.
|
# and only if the refactor method's write parameter was True.
|
||||||
logger = logging.getLogger("RefactoringTool")
|
logger = logging.getLogger("RefactoringTool")
|
||||||
d = Driver(pytree.python_grammar, convert=self.convert, logger=logger)
|
d = Driver(pytree.python_grammar, convert=self.convert, logger=logger)
|
||||||
print(repr(source))
|
|
||||||
self.module = d.parse_string(source).get_parent_until()
|
self.module = d.parse_string(source).get_parent_until()
|
||||||
|
|
||||||
self.module.set_global_names(self.global_names)
|
self.module.set_global_names(self.global_names)
|
||||||
|
|||||||
@@ -98,14 +98,14 @@ def convert(grammar, raw_node):
|
|||||||
# its logic.
|
# its logic.
|
||||||
if len(children) == 1 and type != python_symbols.expr_stmt:
|
if len(children) == 1 and type != python_symbols.expr_stmt:
|
||||||
return children[0]
|
return children[0]
|
||||||
print(raw_node, type_repr(type))
|
#print(raw_node, type_repr(type))
|
||||||
#import pdb; pdb.set_trace()
|
#import pdb; pdb.set_trace()
|
||||||
try:
|
try:
|
||||||
return ast_mapping[type](children)
|
return ast_mapping[type](children)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return pr.Node(type, children)
|
return pr.Node(type, children)
|
||||||
else:
|
else:
|
||||||
print('leaf', raw_node, type_repr(type))
|
#print('leaf', raw_node, type_repr(type))
|
||||||
prefix, start_pos = context
|
prefix, start_pos = context
|
||||||
if type == tokenize.NAME:
|
if type == tokenize.NAME:
|
||||||
if value in grammar.keywords:
|
if value in grammar.keywords:
|
||||||
|
|||||||
Reference in New Issue
Block a user