Пример #1
0
    def _analysis(self):
        self._evaluator.is_analysis = True
        self._evaluator.analysis_modules = [self._module_node]
        module = self._get_module()
        try:
            for node in get_executable_nodes(self._module_node):
                context = module.create_context(node)
                if node.type in ('funcdef', 'classdef'):
                    # Resolve the decorators.
                    tree_name_to_contexts(self._evaluator, context,
                                          node.children[1])
                elif isinstance(node, tree.Import):
                    import_names = set(node.get_defined_names())
                    if node.is_nested():
                        import_names |= set(path[-1]
                                            for path in node.get_paths())
                    for n in import_names:
                        imports.infer_import(context, n)
                elif node.type == 'expr_stmt':
                    types = context.eval_node(node)
                    for testlist in node.children[:-1:2]:
                        # Iterate tuples.
                        unpack_tuple_to_dict(context, types, testlist)
                else:
                    if node.type == 'name':
                        defs = self._evaluator.goto_definitions(context, node)
                    else:
                        defs = evaluate_call_of_leaf(context, node)
                    try_iter_content(defs)
                self._evaluator.reset_recursion_limitations()

            ana = [a for a in self._evaluator.analysis if self.path == a.path]
            return sorted(set(ana), key=lambda x: x.line)
        finally:
            self._evaluator.is_analysis = False
Пример #2
0
    def _analysis(self):
        self._evaluator.is_analysis = True
        module_node = self._get_module_node()
        self._evaluator.analysis_modules = [module_node]
        try:
            for node in get_executable_nodes(module_node):
                context = self._get_module().create_context(node)
                if node.type in ('funcdef', 'classdef'):
                    # Resolve the decorators.
                    tree_name_to_contexts(self._evaluator, context, node.children[1])
                elif isinstance(node, tree.Import):
                    import_names = set(node.get_defined_names())
                    if node.is_nested():
                        import_names |= set(path[-1] for path in node.get_paths())
                    for n in import_names:
                        imports.infer_import(context, n)
                elif node.type == 'expr_stmt':
                    types = context.eval_node(node)
                    for testlist in node.children[:-1:2]:
                        # Iterate tuples.
                        unpack_tuple_to_dict(context, types, testlist)
                else:
                    if node.type == 'name':
                        defs = self._evaluator.goto_definitions(context, node)
                    else:
                        defs = evaluate_call_of_leaf(context, node)
                    try_iter_content(defs)
                self._evaluator.reset_recursion_limitations()

            ana = [a for a in self._evaluator.analysis if self.path == a.path]
            return sorted(set(ana), key=lambda x: x.line)
        finally:
            self._evaluator.is_analysis = False
Пример #3
0
    def infer(self):
        # TODO this _name_to_types might get refactored and be a part of the id:478 gh:479
        # parent class. Once it is, we can probably just overwrite method to
        # achieve this.
        from jedi.evaluate.syntax_tree import tree_name_to_contexts
        inferred = tree_name_to_contexts(self.parent_context.evaluator,
                                         self._name_context, self.tree_name)

        for result_context in inferred:
            for c in apply_py__get__(result_context, self.parent_context):
                yield c
Пример #4
0
    def infer(self):
        # TODO this _name_to_types might get refactored and be a part of the
        # parent class. Once it is, we can probably just overwrite method to
        # achieve this.
        from jedi.evaluate.syntax_tree import tree_name_to_contexts
        inferred = tree_name_to_contexts(
            self.parent_context.evaluator, self._name_context, self.tree_name)

        for result_context in inferred:
            for c in apply_py__get__(result_context, self.parent_context):
                yield c
Пример #5
0
    def infer(self):
        # We're using a different context to infer, so we cannot call super().
        from jedi.evaluate.syntax_tree import tree_name_to_contexts
        inferred = tree_name_to_contexts(self.parent_context.evaluator,
                                         self._name_context, self.tree_name)

        for result_context in inferred:
            if self._apply_decorators:
                for c in apply_py__get__(result_context,
                                         instance=None,
                                         class_context=self.parent_context):
                    yield c
            else:
                yield result_context
Пример #6
0
 def infer(self):
     # Refactor this, should probably be here.
     from jedi.evaluate.syntax_tree import tree_name_to_contexts
     parent = self.parent_context
     return tree_name_to_contexts(parent.evaluator, parent, self.tree_name)
Пример #7
0
 def infer(self):
     # Refactor this, should probably be here.
     from jedi.evaluate.syntax_tree import tree_name_to_contexts
     return tree_name_to_contexts(self.parent_context.evaluator, self.parent_context, self.tree_name)