1
0
forked from VimPlug/jedi

Merge branch 'master' into python3

This commit is contained in:
Dave Halter
2020-07-17 16:07:47 +02:00
13 changed files with 171 additions and 49 deletions

View File

@@ -61,7 +61,7 @@ class Environment(_BaseEnvironment):
"""
_subprocess = None
def __init__(self, executable, env_vars={}):
def __init__(self, executable, env_vars=None):
self._start_executable = executable
self._env_vars = env_vars
# Initialize the environment
@@ -126,7 +126,7 @@ class _SameEnvironmentMixin(object):
self._start_executable = self.executable = sys.executable
self.path = sys.prefix
self.version_info = _VersionInfo(*sys.version_info[:3])
self._env_vars = {}
self._env_vars = None
class SameEnvironment(_SameEnvironmentMixin, Environment):
@@ -353,7 +353,7 @@ def get_system_environment(version, *, env_vars={}):
raise InvalidPythonEnvironment("Cannot find executable python%s." % version)
def create_environment(path, *, safe=True, env_vars={}):
def create_environment(path, *, safe=True, env_vars=None):
"""
Make it possible to manually create an Environment object by specifying a
Virtualenv path or an executable path and optional environment variables.

View File

@@ -3,6 +3,9 @@ TODO Some parts of this module are still not well documented.
"""
from jedi.inference import compiled
from jedi.inference.base_value import ValueSet
from jedi.inference.filters import ParserTreeFilter, MergedFilter
from jedi.inference.names import TreeNameDefinition
from jedi.inference.compiled import mixed
from jedi.inference.compiled.access import create_access_path
from jedi.inference.context import ModuleContext
@@ -19,10 +22,37 @@ class NamespaceObject(object):
self.__dict__ = dct
class MixedTreeName(TreeNameDefinition):
def infer(self):
"""
In IPython notebook it is typical that some parts of the code that is
provided was already executed. In that case if something is not properly
inferred, it should still infer from the variables it already knows.
"""
inferred = super(MixedTreeName, self).infer()
if not inferred:
for compiled_value in self.parent_context.mixed_values:
for f in compiled_value.get_filters():
values = ValueSet.from_sets(
n.infer() for n in f.get(self.string_name)
)
if values:
return values
return inferred
class MixedParserTreeFilter(ParserTreeFilter):
name_class = MixedTreeName
class MixedModuleContext(ModuleContext):
def __init__(self, tree_module_value, namespaces):
super().__init__(tree_module_value)
self._namespace_objects = [NamespaceObject(n) for n in namespaces]
self.mixed_values = [
self._get_mixed_object(
_create(self.inference_state, NamespaceObject(n))
) for n in namespaces
]
def _get_mixed_object(self, compiled_value):
return mixed.MixedObject(
@@ -30,12 +60,16 @@ class MixedModuleContext(ModuleContext):
tree_value=self._value
)
def get_filters(self, *args, **kwargs):
for filter in self._value.as_context().get_filters(*args, **kwargs):
yield filter
def get_filters(self, until_position=None, origin_scope=None):
yield MergedFilter(
MixedParserTreeFilter(
parent_context=self,
until_position=until_position,
origin_scope=origin_scope
),
self.get_global_filter(),
)
for namespace_obj in self._namespace_objects:
compiled_value = _create(self.inference_state, namespace_obj)
mixed_object = self._get_mixed_object(compiled_value)
for filter in mixed_object.get_filters(*args, **kwargs):
for mixed_object in self.mixed_values:
for filter in mixed_object.get_filters(until_position, origin_scope):
yield filter