Cleaned up create_context for methods

Some improvements made a lot of things clearer about function/method contexts, therefore
the code is now clearer.
This commit is contained in:
Dave Halter
2019-06-05 10:11:51 +02:00
parent 1139761525
commit b24e782b7d
2 changed files with 6 additions and 9 deletions

View File

@@ -433,18 +433,15 @@ class Evaluator(object):
parent_context = from_scope_node(parent_scope) parent_context = from_scope_node(parent_scope)
if is_funcdef: if is_funcdef:
parent_was_class = parent_context.is_class()
if parent_was_class:
parent_context = AnonymousInstance(
self, parent_context.parent_context, parent_context)
func = FunctionContext.from_context(parent_context, scope_node) func = FunctionContext.from_context(parent_context, scope_node)
if parent_context.is_class():
if parent_was_class: instance = AnonymousInstance(
self, parent_context.parent_context, parent_context)
func = BoundMethod( func = BoundMethod(
instance=parent_context, instance=instance,
function=func function=func
) )
if is_nested and not node_is_object: if is_nested and not node_is_object:
return func.get_function_execution() return func.get_function_execution()
return func return func

View File

@@ -13,7 +13,7 @@ from jedi.evaluate.arguments import AnonymousArguments
from jedi.evaluate.filters import ParserTreeFilter, FunctionExecutionFilter from jedi.evaluate.filters import ParserTreeFilter, FunctionExecutionFilter
from jedi.evaluate.names import ContextName, AbstractNameDefinition, ParamName from jedi.evaluate.names import ContextName, AbstractNameDefinition, ParamName
from jedi.evaluate.base_context import ContextualizedNode, NO_CONTEXTS, \ from jedi.evaluate.base_context import ContextualizedNode, NO_CONTEXTS, \
ContextSet, TreeContext, ContextWrapper, LazyContextWrapper ContextSet, TreeContext, ContextWrapper
from jedi.evaluate.lazy_context import LazyKnownContexts, LazyKnownContext, \ from jedi.evaluate.lazy_context import LazyKnownContexts, LazyKnownContext, \
LazyTreeContext LazyTreeContext
from jedi.evaluate.context import iterable from jedi.evaluate.context import iterable