forked from VimPlug/jedi
Remove pr.Array.type identifiers.
This commit is contained in:
@@ -166,7 +166,7 @@ class ListComprehension(Comprehension):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return FakeSequence(self._evaluator, [], pr.Array.LIST).name
|
||||
return FakeSequence(self._evaluator, [], 'list').name
|
||||
|
||||
|
||||
class GeneratorComprehension(Comprehension, GeneratorMixin):
|
||||
@@ -175,13 +175,9 @@ class GeneratorComprehension(Comprehension, GeneratorMixin):
|
||||
|
||||
|
||||
class Array(IterableWrapper):
|
||||
"""
|
||||
Used as a mirror to pr.Array, if needed. It defines some getter
|
||||
methods which are important in this module.
|
||||
"""
|
||||
mapping = {'(': pr.Array.TUPLE,
|
||||
'[': pr.Array.LIST,
|
||||
'{': pr.Array.DICT}
|
||||
mapping = {'(': 'tuple',
|
||||
'[': 'list',
|
||||
'{': 'dict'}
|
||||
|
||||
def __init__(self, evaluator, atom):
|
||||
self._evaluator = evaluator
|
||||
@@ -190,10 +186,10 @@ class Array(IterableWrapper):
|
||||
|
||||
c = self.atom.children
|
||||
array_node = c[1]
|
||||
if self.type == pr.Array.DICT and array_node != '}' \
|
||||
if self.type == 'dict' and array_node != '}' \
|
||||
and (not hasattr(array_node, 'children')
|
||||
or ':' not in array_node.children):
|
||||
self.type = pr.Array.SET
|
||||
self.type = 'set'
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
@@ -232,7 +228,7 @@ class Array(IterableWrapper):
|
||||
|
||||
def get_exact_index_types(self, mixed_index):
|
||||
""" Here the index is an int/str. Raises IndexError/KeyError """
|
||||
if self.type == pr.Array.DICT:
|
||||
if self.type == 'dict':
|
||||
for key, values in self._items():
|
||||
# Because we only want the key to be a string.
|
||||
keys = self._evaluator.eval_element(key)
|
||||
@@ -275,7 +271,7 @@ class Array(IterableWrapper):
|
||||
|
||||
def _values(self):
|
||||
"""Returns a list of a list of node."""
|
||||
if self.type == pr.Array.DICT:
|
||||
if self.type == 'dict':
|
||||
return list(chain.from_iterable(v for k, v in self._items()))
|
||||
else:
|
||||
return self._items()
|
||||
@@ -320,7 +316,7 @@ class _FakeArray(Array):
|
||||
|
||||
class ImplicitTuple(_FakeArray):
|
||||
def __init__(self, evaluator, testlist):
|
||||
super(ImplicitTuple, self).__init__(evaluator, testlist, pr.Array.TUPLE)
|
||||
super(ImplicitTuple, self).__init__(evaluator, testlist, 'tuple')
|
||||
self._testlist = testlist
|
||||
|
||||
def _items(self):
|
||||
@@ -353,7 +349,7 @@ class MergedNodes(frozenset):
|
||||
|
||||
class FakeDict(_FakeArray):
|
||||
def __init__(self, evaluator, dct):
|
||||
super(FakeDict, self).__init__(evaluator, dct, pr.Array.DICT)
|
||||
super(FakeDict, self).__init__(evaluator, dct, 'dict')
|
||||
self._dct = dct
|
||||
|
||||
def get_exact_index_types(self, index):
|
||||
@@ -424,7 +420,7 @@ def get_iterator_types(inputs):
|
||||
|
||||
def check_array_additions(evaluator, array):
|
||||
""" Just a mapper function for the internal _check_array_additions """
|
||||
if array.type not in (pr.Array.LIST, pr.Array.SET):
|
||||
if array.type not in ('list', 'set'):
|
||||
# TODO also check for dict updates
|
||||
return []
|
||||
|
||||
@@ -442,7 +438,8 @@ def check_array_additions(evaluator, array):
|
||||
@memoize_default([], evaluator_is_first_arg=True)
|
||||
def _check_array_additions(evaluator, compare_array, module, is_list):
|
||||
"""
|
||||
Checks if a `pr.Array` has "add" statements:
|
||||
Checks if a `Array` has "add" (append, insert, extend) statements:
|
||||
|
||||
>>> a = [""]
|
||||
>>> a.append(1)
|
||||
"""
|
||||
|
||||
@@ -255,7 +255,7 @@ def get_params(evaluator, func, var_args):
|
||||
array_type = None
|
||||
if param.stars == 1:
|
||||
# *args param
|
||||
array_type = pr.Array.TUPLE
|
||||
array_type = 'tuple'
|
||||
lst_values = [iterable.MergedNodes(va_values)] if va_values else []
|
||||
for key, va_values in var_arg_iterator:
|
||||
# Iterate until a key argument is found.
|
||||
@@ -264,11 +264,11 @@ def get_params(evaluator, func, var_args):
|
||||
break
|
||||
if va_values:
|
||||
lst_values.append(iterable.MergedNodes(va_values))
|
||||
seq = iterable.FakeSequence(evaluator, lst_values, pr.Array.TUPLE)
|
||||
seq = iterable.FakeSequence(evaluator, lst_values, 'tuple')
|
||||
values = [iterable.AlreadyEvaluated([seq])]
|
||||
elif param.stars == 2:
|
||||
# **kwargs param
|
||||
array_type = pr.Array.DICT
|
||||
array_type = 'dict'
|
||||
dct = iterable.FakeDict(evaluator, dict(non_matching_keys))
|
||||
values = [iterable.AlreadyEvaluated([dct])]
|
||||
non_matching_keys = {}
|
||||
@@ -372,7 +372,7 @@ def _star_star_dict(evaluator, array, input_node, func):
|
||||
|
||||
if isinstance(array, iterable.FakeDict):
|
||||
return array._dct
|
||||
elif isinstance(array, iterable.Array) and array.type == pr.Array.DICT:
|
||||
elif isinstance(array, iterable.Array) and array.type == 'dict':
|
||||
# TODO bad call to non-public API
|
||||
for key_node, values in array._items():
|
||||
for key in evaluator.eval_element(key_node):
|
||||
|
||||
@@ -115,12 +115,12 @@ def is_literal(obj):
|
||||
|
||||
def _is_tuple(obj):
|
||||
from jedi.evaluate import iterable
|
||||
return isinstance(obj, iterable.Array) and obj.type == pr.Array.TUPLE
|
||||
return isinstance(obj, iterable.Array) and obj.type == 'tuple'
|
||||
|
||||
|
||||
def _is_list(obj):
|
||||
from jedi.evaluate import iterable
|
||||
return isinstance(obj, iterable.Array) and obj.type == pr.Array.LIST
|
||||
return isinstance(obj, iterable.Array) and obj.type == 'list'
|
||||
|
||||
|
||||
def _element_calculate(evaluator, left, operator, right):
|
||||
|
||||
@@ -66,7 +66,7 @@ def wrap(evaluator, element):
|
||||
class Executed(pr.Base):
|
||||
"""
|
||||
An instance is also an executable - because __init__ is called
|
||||
:param var_args: The param input array, consist of `pr.Array` or list.
|
||||
:param var_args: The param input array, consist of a parser node or a list.
|
||||
"""
|
||||
def __init__(self, evaluator, base, var_args=()):
|
||||
self._evaluator = evaluator
|
||||
|
||||
@@ -156,7 +156,7 @@ def builtins_reversed(evaluator, sequences, obj):
|
||||
# would fail in certain cases like `reversed(x).__iter__` if we
|
||||
# just returned the result directly.
|
||||
rev = iterable.AlreadyEvaluated(
|
||||
[iterable.FakeSequence(evaluator, rev, pr.Array.LIST)]
|
||||
[iterable.FakeSequence(evaluator, rev, 'list')]
|
||||
)
|
||||
return [er.Instance(evaluator, obj, param.Arguments(evaluator, [rev]))]
|
||||
|
||||
|
||||
@@ -1244,15 +1244,6 @@ class Param(Base):
|
||||
return '<%s: %s>' % (type(self).__name__, str(self.tfpdef) + default)
|
||||
|
||||
|
||||
class Array(object):
|
||||
# TODO remove this. Just here because we need these names.
|
||||
NOARRAY = None # just brackets, like `1 * (3 + 2)`
|
||||
TUPLE = 'tuple'
|
||||
LIST = 'list'
|
||||
DICT = 'dict'
|
||||
SET = 'set'
|
||||
|
||||
|
||||
class CompFor(Simple):
|
||||
type = 'comp_for'
|
||||
__slots__ = ()
|
||||
|
||||
Reference in New Issue
Block a user