forked from VimPlug/jedi
Refactor Evaluator.wrap to use the types in a more consequent way.
This commit is contained in:
@@ -4,6 +4,7 @@ TODO Some parts of this module are still not well documented.
|
|||||||
import inspect
|
import inspect
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import copy
|
||||||
|
|
||||||
from jedi._compatibility import builtins
|
from jedi._compatibility import builtins
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
@@ -31,7 +32,7 @@ class MixedModule(object):
|
|||||||
# Usually we are dealing with very small code sizes when it comes to
|
# Usually we are dealing with very small code sizes when it comes to
|
||||||
# interpreter modules. In this case we just copy the whole syntax tree
|
# interpreter modules. In this case we just copy the whole syntax tree
|
||||||
# to be able to modify it.
|
# to be able to modify it.
|
||||||
self._parser_module = helpers.deep_ast_copy(parser_module)
|
self._parser_module = copy.deepcopy(parser_module)
|
||||||
|
|
||||||
for child in self._parser_module.children:
|
for child in self._parser_module.children:
|
||||||
child.parent = self
|
child.parent = self
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ keywords_only_valid_as_leaf = (
|
|||||||
|
|
||||||
|
|
||||||
class Keyword(object):
|
class Keyword(object):
|
||||||
|
type = 'completion_keyword'
|
||||||
|
|
||||||
def __init__(self, evaluator, name, pos):
|
def __init__(self, evaluator, name, pos):
|
||||||
self.name = FakeName(name, self, pos)
|
self.name = FakeName(name, self, pos)
|
||||||
self.start_pos = pos
|
self.start_pos = pos
|
||||||
|
|||||||
@@ -109,15 +109,18 @@ class Evaluator(object):
|
|||||||
self.execution_recursion_detector = recursion.ExecutionRecursionDetector(self)
|
self.execution_recursion_detector = recursion.ExecutionRecursionDetector(self)
|
||||||
|
|
||||||
def wrap(self, element):
|
def wrap(self, element):
|
||||||
if isinstance(element, tree.Class):
|
if isinstance(element, (er.Wrapper, er.InstanceElement,
|
||||||
|
er.ModuleWrapper, er.FunctionExecution, er.Instance, compiled.CompiledObject)) or element is None:
|
||||||
|
# TODO this is so ugly, please refactor.
|
||||||
|
return element
|
||||||
|
|
||||||
|
if element.type == 'classdef':
|
||||||
return er.Class(self, element)
|
return er.Class(self, element)
|
||||||
elif isinstance(element, tree.Function):
|
elif element.type == 'funcdef':
|
||||||
if isinstance(element, tree.Lambda):
|
return er.Function(self, element)
|
||||||
return er.LambdaWrapper(self, element)
|
elif element.type == 'lambda':
|
||||||
else:
|
return er.LambdaWrapper(self, element)
|
||||||
return er.Function(self, element)
|
elif element.type == 'file_input':
|
||||||
elif isinstance(element, (tree.Module)) \
|
|
||||||
and not isinstance(element, er.ModuleWrapper):
|
|
||||||
return er.ModuleWrapper(self, element)
|
return er.ModuleWrapper(self, element)
|
||||||
else:
|
else:
|
||||||
return element
|
return element
|
||||||
|
|||||||
@@ -560,6 +560,10 @@ def global_names_dict_generator(evaluator, scope, position):
|
|||||||
for names_dict in scope.names_dicts(True):
|
for names_dict in scope.names_dicts(True):
|
||||||
yield names_dict, position
|
yield names_dict, position
|
||||||
if hasattr(scope, 'resets_positions'):
|
if hasattr(scope, 'resets_positions'):
|
||||||
|
# TODO This is so ugly, seriously. However there's
|
||||||
|
# currently no good way of influencing
|
||||||
|
# global_names_dict_generator when it comes to certain
|
||||||
|
# objects.
|
||||||
position = None
|
position = None
|
||||||
if scope.type == 'funcdef':
|
if scope.type == 'funcdef':
|
||||||
# The position should be reset if the current scope is a function.
|
# The position should be reset if the current scope is a function.
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ def test_builtin_details():
|
|||||||
var = get_completion('variable', locals())
|
var = get_completion('variable', locals())
|
||||||
f = get_completion('func', locals())
|
f = get_completion('func', locals())
|
||||||
m = get_completion('keyword', locals())
|
m = get_completion('keyword', locals())
|
||||||
print(cls._definition.type)
|
|
||||||
assert cls.type == 'class'
|
assert cls.type == 'class'
|
||||||
assert var.type == 'instance'
|
assert var.type == 'instance'
|
||||||
assert f.type == 'function'
|
assert f.type == 'function'
|
||||||
|
|||||||
Reference in New Issue
Block a user