1
0
forked from VimPlug/jedi

Evaluator -> InferState

This commit is contained in:
Dave Halter
2019-08-15 00:33:49 +02:00
parent 8157d119a7
commit a5dff65142
62 changed files with 768 additions and 768 deletions

View File

@@ -2,7 +2,7 @@ import re
import os
from jedi import debug
from jedi.inference.cache import evaluator_method_cache
from jedi.inference.cache import infer_state_method_cache
from jedi.inference.names import ContextNameMixin, AbstractNameDefinition
from jedi.inference.filters import GlobalNameFilter, ParserTreeFilter, DictFilter, MergedFilter
from jedi.inference import compiled
@@ -27,13 +27,13 @@ class _ModuleAttributeName(AbstractNameDefinition):
def infer(self):
if self._string_value is not None:
s = self._string_value
if self.parent_context.evaluator.environment.version_info.major == 2 \
if self.parent_context.infer_state.environment.version_info.major == 2 \
and not isinstance(s, bytes):
s = s.encode('utf-8')
return ContextSet([
create_simple_object(self.parent_context.evaluator, s)
create_simple_object(self.parent_context.infer_state, s)
])
return compiled.get_string_context_set(self.parent_context.evaluator)
return compiled.get_string_context_set(self.parent_context.infer_state)
class ModuleName(ContextNameMixin, AbstractNameDefinition):
@@ -48,9 +48,9 @@ class ModuleName(ContextNameMixin, AbstractNameDefinition):
return self._name
def iter_module_names(evaluator, paths):
def iter_module_names(infer_state, paths):
# Python modules/packages
for n in evaluator.compiled_subprocess.list_module_names(paths):
for n in infer_state.compiled_subprocess.list_module_names(paths):
yield n
for path in paths:
@@ -75,7 +75,7 @@ def iter_module_names(evaluator, paths):
class SubModuleDictMixin(object):
@evaluator_method_cache()
@infer_state_method_cache()
def sub_modules_dict(self):
"""
Lists modules in the directory of this module (if this module is a
@@ -87,7 +87,7 @@ class SubModuleDictMixin(object):
except AttributeError:
pass
else:
mods = iter_module_names(self.evaluator, method())
mods = iter_module_names(self.infer_state, method())
for name in mods:
# It's obviously a relative import to the current module.
names[name] = SubModuleName(self, name)
@@ -101,7 +101,7 @@ class ModuleMixin(SubModuleDictMixin):
def get_filters(self, search_global=False, until_position=None, origin_scope=None):
yield MergedFilter(
ParserTreeFilter(
self.evaluator,
self.infer_state,
context=self,
until_position=until_position,
origin_scope=origin_scope
@@ -114,7 +114,7 @@ class ModuleMixin(SubModuleDictMixin):
yield star_filter
def py__class__(self):
c, = contexts_from_qualified_names(self.evaluator, u'types', u'ModuleType')
c, = contexts_from_qualified_names(self.infer_state, u'types', u'ModuleType')
return c
def is_module(self):
@@ -124,7 +124,7 @@ class ModuleMixin(SubModuleDictMixin):
return False
@property
@evaluator_method_cache()
@infer_state_method_cache()
def name(self):
return ModuleName(self, self._string_name)
@@ -141,7 +141,7 @@ class ModuleMixin(SubModuleDictMixin):
# Remove PEP 3149 names
return re.sub(r'\.[a-z]+-\d{2}[mud]{0,3}$', '', r.group(1))
@evaluator_method_cache()
@infer_state_method_cache()
def _module_attributes_dict(self):
names = ['__package__', '__doc__', '__name__']
# All the additional module attributes are strings.
@@ -157,8 +157,8 @@ class ModuleMixin(SubModuleDictMixin):
# 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
# to push the star imports into Evaluator.module_cache, if we reenable this.
@evaluator_method_cache([])
# to push the star imports into InferState.module_cache, if we reenable this.
@infer_state_method_cache([])
def star_imports(self):
from jedi.inference.imports import Importer
@@ -166,7 +166,7 @@ class ModuleMixin(SubModuleDictMixin):
for i in self.tree_node.iter_imports():
if i.is_star_import():
new = Importer(
self.evaluator,
self.infer_state,
import_path=i.get_paths()[-1],
module_context=self,
level=i.level
@@ -191,9 +191,9 @@ class ModuleContext(ModuleMixin, TreeContext):
api_type = u'module'
parent_context = None
def __init__(self, evaluator, module_node, file_io, string_names, code_lines, is_package=False):
def __init__(self, infer_state, module_node, file_io, string_names, code_lines, is_package=False):
super(ModuleContext, self).__init__(
evaluator,
infer_state,
parent_context=None,
tree_node=module_node
)
@@ -243,7 +243,7 @@ class ModuleContext(ModuleMixin, TreeContext):
# It is a namespace, now try to find the rest of the
# modules on sys_path or whatever the search_path is.
paths = set()
for s in self.evaluator.get_sys_path():
for s in self.infer_state.get_sys_path():
other = os.path.join(s, self.name.string_name)
if os.path.isdir(other):
paths.add(other)