Make create_instance_context a lot more understandable (and shorter)

This commit is contained in:
Dave Halter
2019-09-04 01:06:25 +02:00
parent 06d2119f51
commit 79f9d78c83
+12 -29
View File
@@ -182,36 +182,19 @@ class _BaseTreeInstance(AbstractInstanceValue):
@inference_state_method_cache() @inference_state_method_cache()
def create_instance_context(self, class_context, node): def create_instance_context(self, class_context, node):
if node.parent.type in ('funcdef', 'classdef'): new = node
node = node.parent while True:
scope = get_parent_scope(node) func_node = new
if scope == class_context.tree_node: new = search_ancestor(new, 'funcdef', 'classdef')
return class_context if class_context.tree_node is new:
else: func = FunctionValue.from_context(class_context, func_node)
parent_context = self.create_instance_context(class_context, scope)
if scope.type == 'funcdef':
func = FunctionValue.from_context(
parent_context,
scope,
)
bound_method = BoundMethod(self, func) bound_method = BoundMethod(self, func)
if scope.name.value == '__init__' and parent_context == class_context: if func_node.name.value == '__init__':
# TODO private access context = bound_method.as_context(self.arguments)
if hasattr(self, 'arguments'):
return bound_method.as_context(self.arguments)
else:
return bound_method.as_context()
else: else:
return bound_method.as_context() context = bound_method.as_context()
elif scope.type == 'classdef': break
class_context = ClassValue(self.inference_state, parent_context, scope) return context.create_context(node)
return class_context.as_context()
elif scope.type in ('comp_for', 'sync_comp_for'):
# Comprehensions currently don't have a special scope in Jedi.
return self.create_instance_context(class_context, scope)
else:
raise NotImplementedError
return class_context
def py__getattribute__alternatives(self, string_name): def py__getattribute__alternatives(self, string_name):
''' '''
@@ -383,7 +366,7 @@ class TreeInstance(_BaseTreeInstance):
class AnonymousInstance(_BaseTreeInstance): class AnonymousInstance(_BaseTreeInstance):
pass arguments = None
class CompiledInstanceName(compiled.CompiledName): class CompiledInstanceName(compiled.CompiledName):