forked from VimPlug/jedi
Get py__simple_getitem__ modifications working for list/dict instances
This commit is contained in:
@@ -164,6 +164,9 @@ class Value(HelperValueMixin, BaseValue):
|
||||
)
|
||||
return NO_VALUES
|
||||
|
||||
def py__simple_getitem__(self, index):
|
||||
raise SimpleGetItemNotFound
|
||||
|
||||
def py__iter__(self, contextualized_node=None):
|
||||
if contextualized_node is not None:
|
||||
from jedi.inference import analysis
|
||||
@@ -376,20 +379,16 @@ class ContextualizedName(ContextualizedNode):
|
||||
|
||||
def _getitem(value, index_values, contextualized_node):
|
||||
# The actual getitem call.
|
||||
simple_getitem = getattr(value, 'py__simple_getitem__', None)
|
||||
|
||||
result = NO_VALUES
|
||||
unused_values = set()
|
||||
for index_value in index_values:
|
||||
if simple_getitem is not None:
|
||||
|
||||
index = index_value.get_safe_value(default=None)
|
||||
if type(index) in (float, int, str, unicode, slice, bytes):
|
||||
try:
|
||||
result |= simple_getitem(index)
|
||||
continue
|
||||
except SimpleGetItemNotFound:
|
||||
pass
|
||||
index = index_value.get_safe_value(default=None)
|
||||
if type(index) in (float, int, str, unicode, slice, bytes):
|
||||
try:
|
||||
result |= value.py__simple_getitem__(index)
|
||||
continue
|
||||
except SimpleGetItemNotFound:
|
||||
pass
|
||||
|
||||
unused_values.add(index_value)
|
||||
|
||||
|
||||
@@ -269,6 +269,14 @@ class TreeInstance(AbstractInstanceValue):
|
||||
class_value, var_args)
|
||||
self.tree_node = class_value.tree_node
|
||||
|
||||
@property
|
||||
def array_type(self):
|
||||
name = self.class_value.py__name__()
|
||||
if name in ['list', 'set', 'dict'] \
|
||||
and self.parent_context.get_root_context().is_builtins_module():
|
||||
return name
|
||||
return None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return ValueName(self, self.class_value.name.tree_name)
|
||||
|
||||
@@ -326,6 +326,15 @@ some_lst[0]
|
||||
#? int str tuple
|
||||
some_lst[1]
|
||||
|
||||
some_lst2 = list([1])
|
||||
some_lst2[3] = ''
|
||||
#? int() str()
|
||||
some_lst2[0]
|
||||
#? str()
|
||||
some_lst2[3]
|
||||
#? int() str()
|
||||
some_lst2[2]
|
||||
|
||||
# -----------------
|
||||
# set setitem/other modifications (should not work)
|
||||
# -----------------
|
||||
@@ -357,3 +366,16 @@ some_dct['x']
|
||||
some_dct['unknown']
|
||||
#? float
|
||||
some_dct['a']
|
||||
|
||||
some_dct = dict({'a': 1, 1: ''})
|
||||
some_dct = dict(a=1, x=''})
|
||||
#? int() str()
|
||||
some_dct['la']
|
||||
some_dct['x'] = list
|
||||
some_dct['y'] = tuple
|
||||
#? list
|
||||
some_dct['x']
|
||||
#? int() str() list tuple
|
||||
some_dct['unknown']
|
||||
#? int() str() list tuple
|
||||
some_dct['a']
|
||||
|
||||
Reference in New Issue
Block a user