Fix some array tests

This commit is contained in:
Dave Halter
2019-08-17 15:42:13 +02:00
parent c6d2aa6da2
commit 2629ff55f3
30 changed files with 252 additions and 226 deletions
+13 -12
View File
@@ -6,8 +6,8 @@ from jedi.inference.gradual.stub_value import StubModuleValue
def _stub_to_python_value_set(stub_value, ignore_compiled=False):
stub_module = stub_value.get_root_value()
if not stub_module.is_stub():
stub_module_context = stub_value.get_root_context()
if not stub_module_context.is_stub():
return ValueSet([stub_value])
was_instance = stub_value.is_instance()
@@ -25,7 +25,7 @@ def _stub_to_python_value_set(stub_value, ignore_compiled=False):
qualified_names = qualified_names[:-1]
was_instance = True
values = _infer_from_stub(stub_module, qualified_names, ignore_compiled)
values = _infer_from_stub(stub_module_context, qualified_names, ignore_compiled)
if was_instance:
values = ValueSet.from_sets(
c.execute_with_values()
@@ -39,9 +39,10 @@ def _stub_to_python_value_set(stub_value, ignore_compiled=False):
return values
def _infer_from_stub(stub_module, qualified_names, ignore_compiled):
def _infer_from_stub(stub_module_context, qualified_names, ignore_compiled):
from jedi.inference.compiled.mixed import MixedObject
assert isinstance(stub_module, (StubModuleValue, MixedObject)), stub_module
stub_module = stub_module_context._value # TODO private!
assert isinstance(stub_module, (StubModuleValue, MixedObject)), stub_module_context
non_stubs = stub_module.non_stub_value_set
if ignore_compiled:
non_stubs = non_stubs.filter(lambda c: not c.is_compiled())
@@ -53,8 +54,8 @@ def _infer_from_stub(stub_module, qualified_names, ignore_compiled):
@to_list
def _try_stub_to_python_names(names, prefer_stub_to_compiled=False):
for name in names:
module = name.get_root_value()
if not module.is_stub():
module_context = name.get_root_context()
if not module_context.is_stub():
yield name
continue
@@ -63,7 +64,7 @@ def _try_stub_to_python_names(names, prefer_stub_to_compiled=False):
values = NO_VALUES
else:
values = _infer_from_stub(
module,
module_context,
name_list[:-1],
ignore_compiled=prefer_stub_to_compiled,
)
@@ -98,8 +99,8 @@ def _load_stub_module(module):
@to_list
def _python_to_stub_names(names, fallback_to_python=False):
for name in names:
module = name.get_root_value()
if module.is_stub():
module_context = name.get_root_context()
if module_context.is_stub():
yield name
continue
@@ -114,7 +115,7 @@ def _python_to_stub_names(names, fallback_to_python=False):
name_list = name.get_qualified_names()
stubs = NO_VALUES
if name_list is not None:
stub_module = _load_stub_module(module)
stub_module = _load_stub_module(module_context.get_value())
if stub_module is not None:
stubs = ValueSet({stub_module})
for name in name_list[:-1]:
@@ -171,7 +172,7 @@ def to_stub(value):
value = value.py__class__()
qualified_names = value.get_qualified_names()
stub_module = _load_stub_module(value.get_root_value())
stub_module = _load_stub_module(value.get_root_context().get_value())
if stub_module is None or qualified_names is None:
return NO_VALUES
+18 -30
View File
@@ -32,26 +32,18 @@ class StubModuleValue(ModuleValue):
def _get_first_non_stub_filters(self):
for value in self.non_stub_value_set:
yield next(value.get_filters(search_global=False))
yield next(value.get_filters())
def _get_stub_filters(self, search_global, **filter_kwargs):
def _get_stub_filters(self, origin_scope):
return [StubFilter(
value=self,
search_global=search_global,
**filter_kwargs
)] + list(self.iter_star_filters(search_global=search_global))
context=self.as_context(),
origin_scope=origin_scope
)] + list(self.iter_star_filters())
def get_filters(self, search_global=False, until_position=None,
origin_scope=None, **kwargs):
filters = super(StubModuleValue, self).get_filters(
search_global, until_position, origin_scope, **kwargs
)
def get_filters(self, origin_scope=None):
filters = super(StubModuleValue, self).get_filters(origin_scope)
next(filters) # Ignore the first filter and replace it with our own
stub_filters = self._get_stub_filters(
search_global=search_global,
until_position=until_position,
origin_scope=origin_scope,
)
stub_filters = self._get_stub_filters(origin_scope=origin_scope)
for f in stub_filters:
yield f
@@ -71,7 +63,7 @@ class TypingModuleWrapper(StubModuleValue):
class _StubName(TreeNameDefinition):
def infer(self):
inferred = super(_StubName, self).infer()
if self.string_name == 'version_info' and self.get_root_value().py__name__() == 'sys':
if self.string_name == 'version_info' and self.get_root_context().py__name__() == 'sys':
return [VersionInfo(c) for c in inferred]
return inferred
@@ -79,24 +71,20 @@ class _StubName(TreeNameDefinition):
class StubFilter(ParserTreeFilter):
name_class = _StubName
def __init__(self, *args, **kwargs):
self._search_global = kwargs.pop('search_global') # Python 2 :/
super(StubFilter, self).__init__(*args, **kwargs)
def _is_name_reachable(self, name):
if not super(StubFilter, self)._is_name_reachable(name):
return False
if not self._search_global:
# Imports in stub files are only public if they have an "as"
# export.
definition = name.get_definition()
if definition.type in ('import_from', 'import_name'):
if name.parent.type not in ('import_as_name', 'dotted_as_name'):
return False
n = name.value
if n.startswith('_') and not (n.startswith('__') and n.endswith('__')):
# Imports in stub files are only public if they have an "as"
# export.
definition = name.get_definition()
if definition.type in ('import_from', 'import_name'):
if name.parent.type not in ('import_as_name', 'dotted_as_name'):
return False
n = name.value
# TODO rewrite direct return
if n.startswith('_') and not (n.startswith('__') and n.endswith('__')):
return False
return True
+4 -5
View File
@@ -198,7 +198,7 @@ class TypingValue(_BaseTypingValue):
self.parent_context,
self._tree_name,
index_value,
value_of_index=valueualized_node.value)
value_of_index=valueualized_node.context)
for index_value in index_value_set
)
@@ -213,7 +213,7 @@ class _TypingClassMixin(object):
return []
class TypingClassValueWithIndex(_TypingClassMixin, TypingValueWithIndex, ClassMixin):
class TypingClassValueWithIndex(_TypingClassMixin, ClassMixin, TypingValueWithIndex):
pass
@@ -470,7 +470,7 @@ class NewTypeFunction(_BaseTypingValue):
return ValueSet(
NewType(
self.inference_state,
valueualized_node.value,
valueualized_node.context,
valueualized_node.node,
second_arg.infer(),
) for valueualized_node in arguments.get_calling_nodes())
@@ -553,9 +553,8 @@ class AbstractAnnotatedClass(ClassMixin, ValueWrapper):
def get_type_var_filter(self):
return TypeVarFilter(self.get_generics(), self.list_type_vars())
def get_filters(self, search_global=False, *args, **kwargs):
def get_filters(self, *args, **kwargs):
filters = super(AbstractAnnotatedClass, self).get_filters(
search_global,
*args, **kwargs
)
for f in filters: