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