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
|
return NO_VALUES
|
||||||
|
|
||||||
|
def py__simple_getitem__(self, index):
|
||||||
|
raise SimpleGetItemNotFound
|
||||||
|
|
||||||
def py__iter__(self, contextualized_node=None):
|
def py__iter__(self, contextualized_node=None):
|
||||||
if contextualized_node is not None:
|
if contextualized_node is not None:
|
||||||
from jedi.inference import analysis
|
from jedi.inference import analysis
|
||||||
@@ -376,20 +379,16 @@ class ContextualizedName(ContextualizedNode):
|
|||||||
|
|
||||||
def _getitem(value, index_values, contextualized_node):
|
def _getitem(value, index_values, contextualized_node):
|
||||||
# The actual getitem call.
|
# The actual getitem call.
|
||||||
simple_getitem = getattr(value, 'py__simple_getitem__', None)
|
|
||||||
|
|
||||||
result = NO_VALUES
|
result = NO_VALUES
|
||||||
unused_values = set()
|
unused_values = set()
|
||||||
for index_value in index_values:
|
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):
|
||||||
index = index_value.get_safe_value(default=None)
|
try:
|
||||||
if type(index) in (float, int, str, unicode, slice, bytes):
|
result |= value.py__simple_getitem__(index)
|
||||||
try:
|
continue
|
||||||
result |= simple_getitem(index)
|
except SimpleGetItemNotFound:
|
||||||
continue
|
pass
|
||||||
except SimpleGetItemNotFound:
|
|
||||||
pass
|
|
||||||
|
|
||||||
unused_values.add(index_value)
|
unused_values.add(index_value)
|
||||||
|
|
||||||
|
|||||||
@@ -269,6 +269,14 @@ class TreeInstance(AbstractInstanceValue):
|
|||||||
class_value, var_args)
|
class_value, var_args)
|
||||||
self.tree_node = class_value.tree_node
|
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
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return ValueName(self, self.class_value.name.tree_name)
|
return ValueName(self, self.class_value.name.tree_name)
|
||||||
|
|||||||
@@ -326,6 +326,15 @@ some_lst[0]
|
|||||||
#? int str tuple
|
#? int str tuple
|
||||||
some_lst[1]
|
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)
|
# set setitem/other modifications (should not work)
|
||||||
# -----------------
|
# -----------------
|
||||||
@@ -357,3 +366,16 @@ some_dct['x']
|
|||||||
some_dct['unknown']
|
some_dct['unknown']
|
||||||
#? float
|
#? float
|
||||||
some_dct['a']
|
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