mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-21 13:01:14 +08:00
InferState -> InferenceState
This commit is contained in:
@@ -28,7 +28,7 @@ from jedi.api import helpers
|
|||||||
from jedi.api.completion import Completion
|
from jedi.api.completion import Completion
|
||||||
from jedi.api.environment import InterpreterEnvironment
|
from jedi.api.environment import InterpreterEnvironment
|
||||||
from jedi.api.project import get_default_project, Project
|
from jedi.api.project import get_default_project, Project
|
||||||
from jedi.inference import InferState
|
from jedi.inference import InferenceState
|
||||||
from jedi.inference import imports
|
from jedi.inference import imports
|
||||||
from jedi.inference import usages
|
from jedi.inference import usages
|
||||||
from jedi.inference.arguments import try_iter_content
|
from jedi.inference.arguments import try_iter_content
|
||||||
@@ -111,7 +111,7 @@ class Script(object):
|
|||||||
# TODO deprecate and remove sys_path from the Script API.
|
# TODO deprecate and remove sys_path from the Script API.
|
||||||
if sys_path is not None:
|
if sys_path is not None:
|
||||||
project._sys_path = sys_path
|
project._sys_path = sys_path
|
||||||
self._infer_state = InferState(
|
self._infer_state = InferenceState(
|
||||||
project, environment=environment, script_path=self.path
|
project, environment=environment, script_path=self.path
|
||||||
)
|
)
|
||||||
debug.speed('init')
|
debug.speed('init')
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from collections import namedtuple
|
|||||||
from jedi._compatibility import highest_pickle_protocol, which
|
from jedi._compatibility import highest_pickle_protocol, which
|
||||||
from jedi.cache import memoize_method, time_cache
|
from jedi.cache import memoize_method, time_cache
|
||||||
from jedi.inference.compiled.subprocess import CompiledSubprocess, \
|
from jedi.inference.compiled.subprocess import CompiledSubprocess, \
|
||||||
InferStateSameProcess, InferStateSubprocess
|
InferenceStateSameProcess, InferenceStateSubprocess
|
||||||
|
|
||||||
import parso
|
import parso
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ class Environment(_BaseEnvironment):
|
|||||||
return '<%s: %s in %s>' % (self.__class__.__name__, version, self.path)
|
return '<%s: %s in %s>' % (self.__class__.__name__, version, self.path)
|
||||||
|
|
||||||
def get_infer_state_subprocess(self, infer_state):
|
def get_infer_state_subprocess(self, infer_state):
|
||||||
return InferStateSubprocess(infer_state, self._get_subprocess())
|
return InferenceStateSubprocess(infer_state, self._get_subprocess())
|
||||||
|
|
||||||
@memoize_method
|
@memoize_method
|
||||||
def get_sys_path(self):
|
def get_sys_path(self):
|
||||||
@@ -141,7 +141,7 @@ class SameEnvironment(_SameEnvironmentMixin, Environment):
|
|||||||
|
|
||||||
class InterpreterEnvironment(_SameEnvironmentMixin, _BaseEnvironment):
|
class InterpreterEnvironment(_SameEnvironmentMixin, _BaseEnvironment):
|
||||||
def get_infer_state_subprocess(self, infer_state):
|
def get_infer_state_subprocess(self, infer_state):
|
||||||
return InferStateSameProcess(infer_state)
|
return InferenceStateSameProcess(infer_state)
|
||||||
|
|
||||||
def get_sys_path(self):
|
def get_sys_path(self):
|
||||||
return sys.path
|
return sys.path
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ return the ``date`` class.
|
|||||||
|
|
||||||
To *visualize* this (simplified):
|
To *visualize* this (simplified):
|
||||||
|
|
||||||
- ``InferState.infer_expr_stmt`` doesn't do much, because there's no assignment.
|
- ``InferenceState.infer_expr_stmt`` doesn't do much, because there's no assignment.
|
||||||
- ``Value.infer_node`` cares for resolving the dotted path
|
- ``Value.infer_node`` cares for resolving the dotted path
|
||||||
- ``InferState.find_types`` searches for global definitions of datetime, which
|
- ``InferenceState.find_types`` searches for global definitions of datetime, which
|
||||||
it finds in the definition of an import, by scanning the syntax tree.
|
it finds in the definition of an import, by scanning the syntax tree.
|
||||||
- Using the import logic, the datetime module is found.
|
- Using the import logic, the datetime module is found.
|
||||||
- Now ``find_types`` is called again by ``infer_node`` to find ``date``
|
- Now ``find_types`` is called again by ``infer_node`` to find ``date``
|
||||||
@@ -85,7 +85,7 @@ from jedi.inference.syntax_tree import infer_trailer, infer_expr_stmt, \
|
|||||||
from jedi.plugins import plugin_manager
|
from jedi.plugins import plugin_manager
|
||||||
|
|
||||||
|
|
||||||
class InferState(object):
|
class InferenceState(object):
|
||||||
def __init__(self, project, environment=None, script_path=None):
|
def __init__(self, project, environment=None, script_path=None):
|
||||||
if environment is None:
|
if environment is None:
|
||||||
environment = project.get_environment()
|
environment = project.get_environment()
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ def _cleanup_process(process, thread):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class _InferStateProcess(object):
|
class _InferenceStateProcess(object):
|
||||||
def __init__(self, infer_state):
|
def __init__(self, infer_state):
|
||||||
self._infer_state_weakref = weakref.ref(infer_state)
|
self._infer_state_weakref = weakref.ref(infer_state)
|
||||||
self._infer_state_id = id(infer_state)
|
self._infer_state_id = id(infer_state)
|
||||||
@@ -93,19 +93,19 @@ class _InferStateProcess(object):
|
|||||||
self._handles[handle.id] = handle
|
self._handles[handle.id] = handle
|
||||||
|
|
||||||
|
|
||||||
class InferStateSameProcess(_InferStateProcess):
|
class InferenceStateSameProcess(_InferenceStateProcess):
|
||||||
"""
|
"""
|
||||||
Basically just an easy access to functions.py. It has the same API
|
Basically just an easy access to functions.py. It has the same API
|
||||||
as InferStateSubprocess and does the same thing without using a subprocess.
|
as InferenceStateSubprocess and does the same thing without using a subprocess.
|
||||||
This is necessary for the Interpreter process.
|
This is necessary for the Interpreter process.
|
||||||
"""
|
"""
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
return partial(_get_function(name), self._infer_state_weakref())
|
return partial(_get_function(name), self._infer_state_weakref())
|
||||||
|
|
||||||
|
|
||||||
class InferStateSubprocess(_InferStateProcess):
|
class InferenceStateSubprocess(_InferenceStateProcess):
|
||||||
def __init__(self, infer_state, compiled_subprocess):
|
def __init__(self, infer_state, compiled_subprocess):
|
||||||
super(InferStateSubprocess, self).__init__(infer_state)
|
super(InferenceStateSubprocess, self).__init__(infer_state)
|
||||||
self._used = False
|
self._used = False
|
||||||
self._compiled_subprocess = compiled_subprocess
|
self._compiled_subprocess = compiled_subprocess
|
||||||
|
|
||||||
@@ -288,17 +288,17 @@ class Listener(object):
|
|||||||
self._infer_states = {}
|
self._infer_states = {}
|
||||||
# TODO refactor so we don't need to process anymore just handle
|
# TODO refactor so we don't need to process anymore just handle
|
||||||
# controlling.
|
# controlling.
|
||||||
self._process = _InferStateProcess(Listener)
|
self._process = _InferenceStateProcess(Listener)
|
||||||
self._pickle_protocol = pickle_protocol
|
self._pickle_protocol = pickle_protocol
|
||||||
|
|
||||||
def _get_infer_state(self, function, infer_state_id):
|
def _get_infer_state(self, function, infer_state_id):
|
||||||
from jedi.inference import InferState
|
from jedi.inference import InferenceState
|
||||||
|
|
||||||
try:
|
try:
|
||||||
infer_state = self._infer_states[infer_state_id]
|
infer_state = self._infer_states[infer_state_id]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
from jedi.api.environment import InterpreterEnvironment
|
from jedi.api.environment import InterpreterEnvironment
|
||||||
infer_state = InferState(
|
infer_state = InferenceState(
|
||||||
# The project is not actually needed. Nothing should need to
|
# The project is not actually needed. Nothing should need to
|
||||||
# access it.
|
# access it.
|
||||||
project=None,
|
project=None,
|
||||||
@@ -399,7 +399,7 @@ class AccessHandle(object):
|
|||||||
|
|
||||||
@memoize_method
|
@memoize_method
|
||||||
def _cached_results(self, name, *args, **kwargs):
|
def _cached_results(self, name, *args, **kwargs):
|
||||||
#if type(self._subprocess) == InferStateSubprocess:
|
#if type(self._subprocess) == InferenceStateSubprocess:
|
||||||
#print(name, args, kwargs,
|
#print(name, args, kwargs,
|
||||||
#self._subprocess.get_compiled_method_return(self.id, name, *args, **kwargs)
|
#self._subprocess.get_compiled_method_return(self.id, name, *args, **kwargs)
|
||||||
#)
|
#)
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ class ModuleMixin(SubModuleDictMixin):
|
|||||||
|
|
||||||
# I'm not sure if the star import cache is really that effective anymore
|
# 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
|
# with all the other really fast import caches. Recheck. Also we would need
|
||||||
# to push the star imports into InferState.module_cache, if we reenable this.
|
# to push the star imports into InferenceState.module_cache, if we reenable this.
|
||||||
@infer_state_method_cache([])
|
@infer_state_method_cache([])
|
||||||
def star_imports(self):
|
def star_imports(self):
|
||||||
from jedi.inference.imports import Importer
|
from jedi.inference.imports import Importer
|
||||||
|
|||||||
Reference in New Issue
Block a user