Fix most issues with dynamic arrays

This commit is contained in:
Dave Halter
2018-10-29 21:05:12 +01:00
parent a352fc8595
commit 0a67b387c6
5 changed files with 21 additions and 18 deletions

View File

@@ -280,7 +280,6 @@ class ContextualizedName(ContextualizedNode):
def _getitem(context, index_contexts, contextualized_node):
from jedi.evaluate.compiled import CompiledObject
from jedi.evaluate.context.iterable import Slice
# The actual getitem call.

View File

@@ -225,15 +225,6 @@ class AbstractInstanceContext(Context):
class CompiledInstance(AbstractInstanceContext):
def __init__(self, evaluator, parent_context, class_context, var_args):
self._original_var_args = var_args
# I don't think that dynamic append lookups should happen here. That
# sounds more like something that should go to py__iter__.
if class_context.py__name__() in ['list', 'set'] \
and parent_context.get_root_context() == evaluator.builtins_module:
# compare the module path with the builtin name.
if settings.dynamic_array_additions:
var_args = iterable.get_dynamic_array_instance(self, var_args)
super(CompiledInstance, self).__init__(evaluator, parent_context, class_context, var_args)
@property
@@ -256,6 +247,14 @@ class CompiledInstance(AbstractInstanceContext):
class TreeInstance(AbstractInstanceContext):
def __init__(self, evaluator, parent_context, class_context, var_args):
# I don't think that dynamic append lookups should happen here. That
# sounds more like something that should go to py__iter__.
if class_context.py__name__() in ['list', 'set'] \
and parent_context.get_root_context() == evaluator.builtins_module:
# compare the module path with the builtin name.
if settings.dynamic_array_additions:
var_args = iterable.get_dynamic_array_instance(self, var_args)
super(TreeInstance, self).__init__(evaluator, parent_context,
class_context, var_args)
self.tree_node = class_context.tree_node

View File

@@ -38,7 +38,7 @@ from jedi.evaluate.helpers import execute_evaluated
from jedi.evaluate.filters import ParserTreeFilter, BuiltinOverwrite, \
publish_method
from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS, \
TreeContext, ContextualizedNode, iterate_contexts
TreeContext, ContextualizedNode, iterate_contexts, HelperContextMixin
from jedi.parser_utils import get_comp_fors
@@ -637,8 +637,8 @@ def _check_array_additions(context, sequence):
if add_name in ['insert']:
params = params[1:]
if add_name in ['append', 'add', 'insert']:
for key, whatever in params:
result.add(whatever)
for key, lazy_context in params:
result.add(lazy_context)
elif add_name in ['extend', 'update']:
for key, lazy_context in params:
result |= set(lazy_context.infer().iterate())
@@ -704,7 +704,7 @@ def get_dynamic_array_instance(instance, arguments):
return arguments.ValuesArguments([ContextSet([ai])])
class _ArrayInstance(object):
class _ArrayInstance(HelperContextMixin):
"""
Used for the usage of set() and list().
This is definitely a hack, but a good one :-)
@@ -714,6 +714,10 @@ class _ArrayInstance(object):
self.instance = instance
self.var_args = var_args
def py__class__(self):
tuple_, = self.instance.evaluator.builtins_module.py__getattribute__('tuple')
return tuple_
def py__iter__(self):
var_args = self.var_args
try:

View File

@@ -55,9 +55,10 @@ list(arr)[10]
arr = [1.0]
arr.extend([1,2,3])
arr.extend([])
arr.extend("") # should ignore
arr.extend("")
arr.extend(list) # should ignore
#? float() int()
#? float() int() str()
arr[100]
a = set(arr)
@@ -94,7 +95,7 @@ arr2[0]
lst = [1]
lst.append(1.0)
s = set(lst)
s.add("")
s.add("ahh")
lst = list(s)
lst.append({})