1
0
forked from VimPlug/jedi

Merge branch 'master' into typeshed

This commit is contained in:
Dave Halter
2018-10-02 19:07:59 +02:00
13 changed files with 78 additions and 16 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ As you see Jedi is pretty simple and allows you to concentrate on writing a
good text editor, while still having very good IDE features for Python.
"""
__version__ = '0.12.1'
__version__ = '0.13.1'
from jedi.api import Script, Interpreter, set_debug_function, \
preload_module, names
+18
View File
@@ -179,6 +179,24 @@ class Script(object):
self._pos, self.call_signatures
)
completions = completion.completions()
def iter_import_completions():
for c in completions:
tree_name = c._name.tree_name
if tree_name is None:
continue
definition = tree_name.get_definition()
if definition is not None \
and definition.type in ('import_name', 'import_from'):
yield c
if len(list(iter_import_completions())) > 10:
# For now disable completions if there's a lot of imports that
# might potentially be resolved. This is the case for tensorflow
# and has been fixed for it. This is obviously temporary until we
# have a better solution.
self._evaluator.infer_enabled = False
debug.speed('completions end')
return completions
+10 -5
View File
@@ -184,16 +184,21 @@ def get_default_environment():
if virtual_env is not None:
return virtual_env
for environment in find_system_environments():
return environment
# If no Python Environment is found, use the environment we're already
# If no VirtualEnv is found, use the environment we're already
# using.
return SameEnvironment()
@time_cache(seconds=10 * 60) # 10 Minutes
def get_cached_default_environment():
environment = _get_cached_default_environment()
if environment.path != os.environ.get('VIRTUAL_ENV'):
_get_cached_default_environment.clear_cache()
return _get_cached_default_environment()
return environment
@time_cache(seconds=10 * 60) # 10 Minutes
def _get_cached_default_environment():
return get_default_environment()
+7 -4
View File
@@ -105,14 +105,17 @@ def get_stack_at_position(grammar, code_lines, module_node, pos):
# TODO This is for now not an official parso API that exists purely
# for Jedi.
tokens = grammar._tokenize(code)
for token_ in tokens:
if token_.string == safeword:
for token in tokens:
if token.string == safeword:
raise EndMarkerReached()
elif token_.prefix.endswith(safeword):
elif token.prefix.endswith(safeword):
# This happens with comments.
raise EndMarkerReached()
elif token.string.endswith(safeword):
yield token # Probably an f-string literal that was not finished.
raise EndMarkerReached()
else:
yield token_
yield token
# The code might be indedented, just remove it.
code = dedent(_get_code_for_stack(code_lines, module_node, pos))
+3 -1
View File
@@ -1,6 +1,8 @@
"""
To use Jedi completion in Python interpreter, add the following in your shell
setup (e.g., ``.bashrc``)::
setup (e.g., ``.bashrc``). This works only on Linux/Mac, because readline is
not available on Windows. If you still want Jedi autocompletion in your REPL,
just use IPython instead::
export PYTHONSTARTUP="$(python -m jedi repl)"
+1
View File
@@ -126,6 +126,7 @@ def time_cache(seconds):
wrapper.clear_cache = lambda: cache.clear()
return wrapper
return decorator
+6
View File
@@ -118,6 +118,9 @@ class Evaluator(object):
self.is_analysis = False
self.project = project
self.access_cache = {}
# This setting is only temporary to limit the work we have to do with
# tensorflow and others.
self.infer_enabled = True
self.reset_recursion_limitations()
self.allow_different_encoding = True
@@ -170,6 +173,9 @@ class Evaluator(object):
return self.project._get_sys_path(self, environment=self.environment)
def eval_element(self, context, element):
if not self.infer_enabled:
return NO_CONTEXTS
if isinstance(context, CompForContext):
return eval_node(context, element)
+6 -2
View File
@@ -54,8 +54,12 @@ def get_string_context_set(evaluator):
return execute_evaluated(builtin_from_name(evaluator, u'str'))
def load_module(evaluator, **kwargs):
access_path = evaluator.compiled_subprocess.load_module(**kwargs)
def load_module(evaluator, dotted_name, **kwargs):
# Temporary, some tensorflow builtins cannot be loaded, so it's tried again
# and again and it's really slow.
if dotted_name.startswith('tensorflow.'):
return None
access_path = evaluator.compiled_subprocess.load_module(dotted_name=dotted_name, **kwargs)
if access_path is None:
return None
return create_from_access_path(evaluator, access_path)
+1 -1
View File
@@ -276,7 +276,7 @@ class Importer(object):
return sys_path_mod
def follow(self):
if not self.import_path:
if not self.import_path or not self._evaluator.infer_enabled:
return NO_CONTEXTS
import_names = tuple(