forked from VimPlug/jedi
started writing a new interpreter module that is heavily simplified and fits the current Jedi architecture way better.
This commit is contained in:
@@ -21,9 +21,9 @@ from jedi import debug
|
||||
from jedi import settings
|
||||
from jedi import common
|
||||
from jedi import cache
|
||||
from jedi import interpret
|
||||
from jedi.api import keywords
|
||||
from jedi.api import classes
|
||||
from jedi.api import interpreter
|
||||
from jedi.evaluate import Evaluator, filter_private_variable
|
||||
from jedi.evaluate import representation as er
|
||||
from jedi.evaluate import compiled
|
||||
@@ -150,8 +150,7 @@ class Script(object):
|
||||
if settings.case_insensitive_completion \
|
||||
and n.lower().startswith(like.lower()) \
|
||||
or n.startswith(like):
|
||||
if not filter_private_variable(s,
|
||||
user_stmt or self._parser.user_scope(), n):
|
||||
if not filter_private_variable(s, user_stmt or self._parser.user_scope(), n):
|
||||
new = classes.Completion(self._evaluator, c, needs_dot, len(like), s)
|
||||
k = (new.name, new.complete) # key
|
||||
if k in comp_dct and settings.no_completion_duplicates:
|
||||
@@ -548,7 +547,6 @@ class Script(object):
|
||||
|
||||
|
||||
class Interpreter(Script):
|
||||
|
||||
"""
|
||||
Jedi API for Python REPLs.
|
||||
|
||||
@@ -562,7 +560,6 @@ class Interpreter(Script):
|
||||
>>> script = Interpreter('join().up', [namespace])
|
||||
>>> print(script.completions()[0].name)
|
||||
upper
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, source, namespaces=[], **kwds):
|
||||
@@ -583,9 +580,7 @@ class Interpreter(Script):
|
||||
self.namespaces = namespaces
|
||||
|
||||
# Here we add the namespaces to the current parser.
|
||||
importer = interpret.ObjectImporter(self._parser.user_scope())
|
||||
for ns in namespaces:
|
||||
importer.import_raw_namespace(ns)
|
||||
interpreter.create(namespaces[0], self._parser.module())
|
||||
|
||||
def _simple_complete(self, path, like):
|
||||
user_stmt = self._parser.user_stmt(True)
|
||||
|
||||
35
jedi/api/interpreter.py
Normal file
35
jedi/api/interpreter.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from jedi.evaluate import compiled
|
||||
from jedi.parser import representation as pr
|
||||
from jedi.evaluate import helpers
|
||||
|
||||
|
||||
class InterpreterNamespace(pr.Module):
|
||||
def __init__(self, namespace, parser_module):
|
||||
self.namespace = namespace
|
||||
self.parser_module = parser_module
|
||||
|
||||
def get_defined_names(self):
|
||||
for key, value in self.namespace.items():
|
||||
yield LazyName(key, value)
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self.parser_module, name)
|
||||
|
||||
|
||||
class LazyName(helpers.FakeName):
|
||||
def __init__(self, name, parent_obj):
|
||||
super(LazyName, self).__init__(name)
|
||||
self._parent_obj = parent_obj
|
||||
|
||||
@property
|
||||
def parent(self):
|
||||
return compiled.create(self._parent_obj)
|
||||
|
||||
@parent.setter
|
||||
def parent(self, value):
|
||||
"""Needed because of the ``representation.Simple`` super class."""
|
||||
|
||||
|
||||
def create(namespace, parser_module):
|
||||
ns = InterpreterNamespace(namespace, parser_module)
|
||||
parser_module.statements[0].parent = ns
|
||||
@@ -290,7 +290,7 @@ def create(obj, parent=builtin, module=None):
|
||||
A very weird interface class to this module. The more options provided the
|
||||
more acurate loading compiled objects is.
|
||||
"""
|
||||
if not inspect.ismodule(parent):
|
||||
if not inspect.ismodule(obj):
|
||||
faked = fake.get_faked(module and module.obj, obj)
|
||||
if faked is not None:
|
||||
faked.parent = parent
|
||||
|
||||
Reference in New Issue
Block a user