forked from VimPlug/jedi
Fix some array tests
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from jedi.inference.value.module import ModuleValue
|
||||
from jedi.inference.value.klass import ClassValue
|
||||
from jedi.inference.value.function import FunctionValue, \
|
||||
MethodValue, FunctionExecutionValue
|
||||
MethodValue, FunctionExecutionContext
|
||||
from jedi.inference.value.instance import AnonymousInstance, BoundMethod, \
|
||||
CompiledInstance, AbstractInstanceValue, TreeInstance
|
||||
|
||||
@@ -55,18 +55,11 @@ class FunctionAndClassBase(TreeValue):
|
||||
class FunctionMixin(object):
|
||||
api_type = u'function'
|
||||
|
||||
def get_filters(self, search_global=False, until_position=None, origin_scope=None):
|
||||
if search_global:
|
||||
yield ParserTreeFilter(
|
||||
value=self,
|
||||
until_position=until_position,
|
||||
origin_scope=origin_scope
|
||||
)
|
||||
else:
|
||||
cls = self.py__class__()
|
||||
for instance in cls.execute_with_values():
|
||||
for filter in instance.get_filters(search_global=False, origin_scope=origin_scope):
|
||||
yield filter
|
||||
def get_filters(self, origin_scope=None):
|
||||
cls = self.py__class__()
|
||||
for instance in cls.execute_with_values():
|
||||
for filter in instance.get_filters(origin_scope=origin_scope):
|
||||
yield filter
|
||||
|
||||
def py__get__(self, instance, class_value):
|
||||
from jedi.inference.value.instance import BoundMethod
|
||||
@@ -97,7 +90,7 @@ class FunctionMixin(object):
|
||||
if arguments is None:
|
||||
arguments = AnonymousArguments()
|
||||
|
||||
return FunctionExecutionValue(self.inference_state, self.parent_context, self, arguments)
|
||||
return FunctionExecutionContext(self.inference_state, self.parent_context, self, arguments)
|
||||
|
||||
def get_signatures(self):
|
||||
return [TreeSignature(f) for f in self.get_signature_functions()]
|
||||
@@ -167,11 +160,11 @@ class MethodValue(FunctionValue):
|
||||
return names + (self.py__name__(),)
|
||||
|
||||
|
||||
class FunctionExecutionValue(TreeValue):
|
||||
class FunctionExecutionContext(TreeValue):
|
||||
function_execution_filter = FunctionExecutionFilter
|
||||
|
||||
def __init__(self, inference_state, parent_context, function_value, var_args):
|
||||
super(FunctionExecutionValue, self).__init__(
|
||||
super(FunctionExecutionContext, self).__init__(
|
||||
inference_state,
|
||||
parent_context,
|
||||
function_value.tree_node,
|
||||
@@ -292,7 +285,7 @@ class FunctionExecutionValue(TreeValue):
|
||||
for lazy_value in self.get_yield_lazy_values()
|
||||
)
|
||||
|
||||
def get_filters(self, search_global=False, until_position=None, origin_scope=None):
|
||||
def get_filters(self, until_position=None, origin_scope=None):
|
||||
yield self.function_execution_filter(self,
|
||||
until_position=until_position,
|
||||
origin_scope=origin_scope)
|
||||
|
||||
@@ -122,8 +122,7 @@ class AbstractInstanceValue(Value):
|
||||
else:
|
||||
return ValueSet([self])
|
||||
|
||||
def get_filters(self, search_global=None, until_position=None,
|
||||
origin_scope=None, include_self_names=True):
|
||||
def get_filters(self, origin_scope=None, include_self_names=True):
|
||||
class_value = self.get_annotated_class_object()
|
||||
if include_self_names:
|
||||
for cls in class_value.py__mro__():
|
||||
@@ -135,7 +134,6 @@ class AbstractInstanceValue(Value):
|
||||
yield SelfAttributeFilter(self, cls, origin_scope)
|
||||
|
||||
class_filters = class_value.get_filters(
|
||||
search_global=False,
|
||||
origin_scope=origin_scope,
|
||||
is_instance=True,
|
||||
)
|
||||
@@ -262,7 +260,7 @@ class TreeInstance(AbstractInstanceValue):
|
||||
# I don't think that dynamic append lookups should happen here. That
|
||||
# sounds more like something that should go to py__iter__.
|
||||
if class_value.py__name__() in ['list', 'set'] \
|
||||
and parent_context.get_root_value() == inference_state.builtins_module:
|
||||
and parent_context.get_root_context().is_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)
|
||||
@@ -466,7 +464,10 @@ class InstanceClassFilter(AbstractFilter):
|
||||
return self._convert(self._class_filter.values(from_instance=True))
|
||||
|
||||
def _convert(self, names):
|
||||
return [LazyInstanceClassName(self._instance, self._class_filter.value, n) for n in names]
|
||||
return [
|
||||
LazyInstanceClassName(self._instance, self._class_filter.context, n)
|
||||
for n in names
|
||||
]
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s for %s>' % (self.__class__.__name__, self._class_filter.value)
|
||||
@@ -480,8 +481,8 @@ class SelfAttributeFilter(ClassFilter):
|
||||
|
||||
def __init__(self, value, class_value, origin_scope):
|
||||
super(SelfAttributeFilter, self).__init__(
|
||||
value=value,
|
||||
node_value=class_value,
|
||||
context=value,
|
||||
node_context=class_value.as_context(),
|
||||
origin_scope=origin_scope,
|
||||
is_instance=True,
|
||||
)
|
||||
@@ -503,7 +504,7 @@ class SelfAttributeFilter(ClassFilter):
|
||||
yield name
|
||||
|
||||
def _convert_names(self, names):
|
||||
return [self.name_class(self.value, self._class_value, name) for name in names]
|
||||
return [self.name_class(self.context, self._class_value, name) for name in names]
|
||||
|
||||
def _check_flows(self, names):
|
||||
return names
|
||||
|
||||
@@ -116,7 +116,7 @@ class CompForValue(TreeValue):
|
||||
def from_comp_for(cls, parent_context, comp_for):
|
||||
return cls(parent_context.inference_state, parent_context, comp_for)
|
||||
|
||||
def get_filters(self, search_global=False, until_position=None, origin_scope=None):
|
||||
def get_filters(self, until_position=None, origin_scope=None):
|
||||
yield ParserTreeFilter(self)
|
||||
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ from jedi.inference.names import TreeNameDefinition, ValueName
|
||||
from jedi.inference.arguments import unpack_arglist, ValuesArguments
|
||||
from jedi.inference.base_value import ValueSet, iterator_to_value_set, \
|
||||
NO_VALUES
|
||||
from jedi.inference.context import ClassContext
|
||||
from jedi.inference.value.function import FunctionAndClassBase
|
||||
from jedi.plugins import plugin_manager
|
||||
|
||||
@@ -95,9 +96,9 @@ class ClassFilter(ParserTreeFilter):
|
||||
def _convert_names(self, names):
|
||||
return [
|
||||
self.name_class(
|
||||
parent_context=self.value,
|
||||
parent_context=self.context,
|
||||
tree_name=name,
|
||||
name_value=self._node_value,
|
||||
name_context=self._node_context,
|
||||
apply_decorators=not self._is_instance,
|
||||
) for name in names
|
||||
]
|
||||
@@ -192,26 +193,22 @@ class ClassMixin(object):
|
||||
mro.append(cls_new)
|
||||
yield cls_new
|
||||
|
||||
def get_filters(self, search_global=False, until_position=None,
|
||||
origin_scope=None, is_instance=False):
|
||||
def get_filters(self, origin_scope=None, is_instance=False):
|
||||
metaclasses = self.get_metaclasses()
|
||||
if metaclasses:
|
||||
for f in self.get_metaclass_filters(metaclasses):
|
||||
yield f
|
||||
|
||||
if search_global:
|
||||
yield self.get_global_filter(until_position, origin_scope)
|
||||
else:
|
||||
for cls in self.py__mro__():
|
||||
if isinstance(cls, compiled.CompiledObject):
|
||||
for filter in cls.get_filters(is_instance=is_instance):
|
||||
yield filter
|
||||
else:
|
||||
yield ClassFilter(
|
||||
self, node_value=cls,
|
||||
origin_scope=origin_scope,
|
||||
is_instance=is_instance
|
||||
)
|
||||
for cls in self.py__mro__():
|
||||
if isinstance(cls, compiled.CompiledObject):
|
||||
for filter in cls.get_filters(is_instance=is_instance):
|
||||
yield filter
|
||||
else:
|
||||
yield ClassFilter(
|
||||
self, node_context=cls.as_context(),
|
||||
origin_scope=origin_scope,
|
||||
is_instance=is_instance
|
||||
)
|
||||
if not is_instance:
|
||||
from jedi.inference.compiled import builtin_from_name
|
||||
type_ = builtin_from_name(self.inference_state, u'type')
|
||||
@@ -228,12 +225,8 @@ class ClassMixin(object):
|
||||
init_funcs = self.py__call__().py__getattribute__('__init__')
|
||||
return [sig.bind(self) for sig in init_funcs.get_signatures()]
|
||||
|
||||
def get_global_filter(self, until_position=None, origin_scope=None):
|
||||
return ParserTreeFilter(
|
||||
value=self,
|
||||
until_position=until_position,
|
||||
origin_scope=origin_scope
|
||||
)
|
||||
def as_context(self):
|
||||
return ClassContext(self)
|
||||
|
||||
|
||||
class ClassValue(use_metaclass(CachedMetaClass, ClassMixin, FunctionAndClassBase)):
|
||||
@@ -273,7 +266,7 @@ class ClassValue(use_metaclass(CachedMetaClass, ClassMixin, FunctionAndClassBase
|
||||
return lst
|
||||
|
||||
if self.py__name__() == 'object' \
|
||||
and self.parent_context == self.inference_state.builtins_module:
|
||||
and self.parent_context.is_builtins_module():
|
||||
return []
|
||||
return [LazyKnownValues(
|
||||
self.inference_state.builtins_module.py__getattribute__('object')
|
||||
@@ -287,7 +280,7 @@ class ClassValue(use_metaclass(CachedMetaClass, ClassMixin, FunctionAndClassBase
|
||||
LazyGenericClass(
|
||||
self,
|
||||
index_value,
|
||||
value_of_index=valueualized_node.value,
|
||||
value_of_index=valueualized_node.context,
|
||||
)
|
||||
for index_value in index_value_set
|
||||
)
|
||||
|
||||
@@ -99,11 +99,10 @@ class SubModuleDictMixin(object):
|
||||
|
||||
|
||||
class ModuleMixin(SubModuleDictMixin):
|
||||
def get_filters(self, search_global=False, until_position=None, origin_scope=None):
|
||||
def get_filters(self, origin_scope=None):
|
||||
yield MergedFilter(
|
||||
ParserTreeFilter(
|
||||
value=self,
|
||||
until_position=until_position,
|
||||
context=self.as_context(),
|
||||
origin_scope=origin_scope
|
||||
),
|
||||
GlobalNameFilter(self, self.tree_node),
|
||||
@@ -151,9 +150,9 @@ class ModuleMixin(SubModuleDictMixin):
|
||||
dct['__file__'] = _ModuleAttributeName(self, '__file__', file)
|
||||
return dct
|
||||
|
||||
def iter_star_filters(self, search_global=False):
|
||||
def iter_star_filters(self):
|
||||
for star_module in self.star_imports():
|
||||
yield next(star_module.get_filters(search_global))
|
||||
yield next(star_module.get_filters())
|
||||
|
||||
# I'm not sure if the star import cache is really that effective anymore
|
||||
# with all the other really fast import caches. Recheck. Also we would need
|
||||
@@ -189,7 +188,6 @@ class ModuleMixin(SubModuleDictMixin):
|
||||
|
||||
class ModuleValue(ModuleMixin, TreeValue):
|
||||
api_type = u'module'
|
||||
parent_context = None
|
||||
|
||||
def __init__(self, inference_state, module_node, file_io, string_names,
|
||||
code_lines, is_package=False):
|
||||
|
||||
@@ -31,7 +31,7 @@ class ImplicitNamespaceValue(Value, SubModuleDictMixin):
|
||||
self._fullname = fullname
|
||||
self._paths = paths
|
||||
|
||||
def get_filters(self, search_global=False, until_position=None, origin_scope=None):
|
||||
def get_filters(self, origin_scope=None):
|
||||
yield DictFilter(self.sub_modules_dict())
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user