forked from VimPlug/jedi
FunctionContext should be created from a unified interface
This commit is contained in:
@@ -216,7 +216,7 @@ class Evaluator(object):
|
||||
if type_ == 'classdef':
|
||||
return [ClassContext(self, context, name.parent)]
|
||||
elif type_ == 'funcdef':
|
||||
return [FunctionContext(self, context, name.parent)]
|
||||
return [FunctionContext.from_context(context, name.parent)]
|
||||
|
||||
if type_ == 'expr_stmt':
|
||||
is_simple_name = name.parent.type not in ('power', 'trailer')
|
||||
@@ -340,8 +340,7 @@ class Evaluator(object):
|
||||
parent_context.parent_context, scope_node
|
||||
)
|
||||
else:
|
||||
func = FunctionContext(
|
||||
self,
|
||||
func = FunctionContext.from_context(
|
||||
parent_context,
|
||||
scope_node
|
||||
)
|
||||
|
||||
@@ -44,6 +44,13 @@ class FunctionContext(use_metaclass(CachedMetaClass, TreeContext)):
|
||||
"""
|
||||
api_type = u'function'
|
||||
|
||||
@classmethod
|
||||
def from_context(cls, context, tree_node):
|
||||
while context.is_class():
|
||||
context = context.parent_context
|
||||
|
||||
return cls(context.evaluator, parent_context=context, tree_node=tree_node)
|
||||
|
||||
def get_filters(self, search_global, until_position=None, origin_scope=None):
|
||||
if search_global:
|
||||
yield ParserTreeFilter(
|
||||
|
||||
@@ -28,7 +28,6 @@ class InstanceFunctionExecution(BaseInstanceFunctionExecution):
|
||||
|
||||
super(InstanceFunctionExecution, self).__init__(
|
||||
instance, parent_context, function_context, var_args)
|
||||
print(parent_context, self.parent_context, function_context)
|
||||
|
||||
|
||||
class AnonymousInstanceFunctionExecution(BaseInstanceFunctionExecution):
|
||||
@@ -355,9 +354,6 @@ class LazyInstanceClassName(SelfName):
|
||||
# functions. Only other functions and modules will resolve
|
||||
# those things.
|
||||
parent_context = result_context.parent_context
|
||||
while parent_context.is_class():
|
||||
parent_context = parent_context.parent_context
|
||||
|
||||
yield BoundMethod(
|
||||
result_context.evaluator, self._instance, self.class_context,
|
||||
parent_context, result_context.tree_node
|
||||
|
||||
@@ -71,7 +71,7 @@ def eval_node(context, element):
|
||||
if typ in ('name', 'number', 'string', 'atom', 'strings', 'keyword'):
|
||||
return eval_atom(context, element)
|
||||
elif typ == 'lambdef':
|
||||
return ContextSet(FunctionContext(evaluator, context, element))
|
||||
return ContextSet(FunctionContext.from_context(context, element))
|
||||
elif typ == 'expr_stmt':
|
||||
return eval_expr_stmt(context, element)
|
||||
elif typ in ('power', 'atom_expr'):
|
||||
@@ -583,11 +583,7 @@ def _apply_decorators(context, node):
|
||||
tree_node=node
|
||||
)
|
||||
else:
|
||||
decoratee_context = FunctionContext(
|
||||
context.evaluator,
|
||||
parent_context=context,
|
||||
tree_node=node
|
||||
)
|
||||
decoratee_context = FunctionContext.from_context(context, node)
|
||||
initial = values = ContextSet(decoratee_context)
|
||||
for dec in reversed(node.get_decorators()):
|
||||
debug.dbg('decorator: %s %s', dec, values)
|
||||
|
||||
Reference in New Issue
Block a user