Beispiel #1
0
def create(evaluator, obj, parent_context=None, module=None, faked=None):
    """
    A very weird interface class to this module. The more options provided the
    more acurate loading compiled objects is.
    """
    if inspect.ismodule(obj):
        if parent_context is not None:
            # Modules don't have parents, be careful with caching: recurse.
            return create(evaluator, obj)
    else:
        if parent_context is None and obj is not _builtins:
            return create(evaluator, obj, create(evaluator, _builtins))

        try:
            faked = fake.get_faked(evaluator,
                                   module,
                                   obj,
                                   parent_context=parent_context)
            if faked.type == 'funcdef':
                from jedi.evaluate.context.function import FunctionContext
                return FunctionContext(evaluator, parent_context, faked)
        except fake.FakeDoesNotExist:
            pass

    return CompiledObject(evaluator, obj, parent_context, faked)
Beispiel #2
0
 def create_instance_context(self, class_context, node):
     if node.parent.type in ('funcdef', 'classdef'):
         node = node.parent
     scope = get_parent_scope(node)
     if scope == class_context.tree_node:
         return class_context
     else:
         parent_context = self.create_instance_context(class_context, scope)
         if scope.type == 'funcdef':
             func = FunctionContext.from_context(
                 parent_context,
                 scope,
             )
             bound_method = BoundMethod(self, func)
             if scope.name.value == '__init__' and parent_context == class_context:
                 return bound_method.get_function_execution(self.var_args)
             else:
                 return bound_method.get_function_execution()
         elif scope.type == 'classdef':
             class_context = ClassContext(self.evaluator, parent_context, scope)
             return class_context
         elif scope.type == '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
Beispiel #3
0
 def create_instance_context(self, class_context, node):
     if node.parent.type in ('funcdef', 'classdef'):
         node = node.parent
     scope = get_parent_scope(node)
     if scope == class_context.tree_node:
         return class_context
     else:
         parent_context = self.create_instance_context(class_context, scope)
         if scope.type == 'funcdef':
             func = FunctionContext.from_context(
                 parent_context,
                 scope,
             )
             bound_method = BoundMethod(self, class_context, func)
             if scope.name.value == '__init__' and parent_context == class_context:
                 return self._create_init_execution(class_context, bound_method)
             else:
                 return bound_method.get_function_execution()
         elif scope.type == 'classdef':
             class_context = ClassContext(self.evaluator, parent_context, scope)
             return class_context
         elif scope.type == '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
Beispiel #4
0
 def create_init_executions(self):
     for name in self.get_function_slot_names(u'__init__'):
         if isinstance(name, LazyInstanceClassName):
             function = FunctionContext.from_context(
                 self.parent_context, name.tree_name.parent)
             bound_method = BoundMethod(self, name.class_context, function)
             yield self._create_init_execution(name.class_context,
                                               bound_method)
Beispiel #5
0
 def create_init_executions(self):
     for name in self.get_function_slot_names(u'__init__'):
         # TODO is this correct? I think we need to check for functions.
         if isinstance(name, LazyInstanceClassName):
             function = FunctionContext.from_context(
                 self.parent_context, name.tree_name.parent)
             bound_method = BoundMethod(self, function)
             yield bound_method.get_function_execution(self.var_args)
Beispiel #6
0
 def create_init_executions(self):
     for name in self.get_function_slot_names(u'__init__'):
         if isinstance(name, LazyInstanceClassName):
             function = FunctionContext.from_context(
                 self.parent_context,
                 name.tree_name.parent
             )
             bound_method = BoundMethod(self, name.class_context, function)
             yield self._create_init_execution(name.class_context, bound_method)
Beispiel #7
0
 def py__call__(self, params):
     if self.tree_node is not None and self.tree_node.type == 'funcdef':
         from jedi.evaluate.context.function import FunctionContext
         return FunctionContext(self.evaluator,
                                parent_context=self.parent_context,
                                funcdef=self.tree_node).py__call__(params)
     if self.access_handle.is_class():
         from jedi.evaluate.context import CompiledInstance
         return ContextSet(
             CompiledInstance(self.evaluator, self.parent_context, self,
                              params))
     else:
         return ContextSet.from_iterable(self._execute_function(params))
Beispiel #8
0
def _create_from_name(evaluator, module, compiled_object, name):
    obj = compiled_object.obj
    faked = None
    try:
        faked = fake.get_faked(evaluator,
                               module,
                               obj,
                               parent_context=compiled_object,
                               name=name)
        if faked.type == 'funcdef':
            from jedi.evaluate.context.function import FunctionContext
            return FunctionContext(evaluator, compiled_object, faked)
    except fake.FakeDoesNotExist:
        pass

    try:
        obj = getattr(obj, name)
    except AttributeError:
        # Happens e.g. in properties of
        # PyQt4.QtGui.QStyleOptionComboBox.currentText
        # -> just set it to None
        obj = None
    return create(evaluator, obj, parent_context=compiled_object, faked=faked)