Esempio n. 1
0
 def visit_str_helper(self, value: str, node: ast.AST) -> None:
     parent = first_occurrence(node, *C.ASTFunctionTuple)
     is_annassign_or_arg = any(
         isinstance(parent, (ast.AnnAssign, ast.arg))
         for parent in get_parents(node))
     if is_annassign_or_arg or (parent is not None
                                and parent.returns is node):
         self.join_visit(value, node)
Esempio n. 2
0
    def visit_CFN(self, node: C.CFNT) -> None:
        Scope.add_current_scope(node)

        if not first_occurrence(node, C.DefTuple):
            self.suggestions_nodes.append(node)

        self.generic_visit(node)

        Scope.remove_current_scope()
Esempio n. 3
0
 def visit_str_helper(self, value: str, node: ast.AST) -> None:
     parent = first_occurrence(node, *ASTFunctionTuple)
     is_annassign_or_arg = any(
         isinstance(parent, (ast.AnnAssign, ast.arg))
         for parent in get_parents(node))
     if is_annassign_or_arg or (parent is not None
                                and parent.returns is node):
         self.traverse(value, mode="eval",
                       parent=node.parent)  # type: ignore
Esempio n. 4
0
    def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
        """
        When include_star_import becomes True, instead of suggesting star,
        it analyses function names and suggests one of the analyzed function's name.

        E.g.: from os import *
        print(walk)

        At this point from os import * becomes > from os import walk
        """
        if not first_occurrence(node, ast.ClassDef):
            self.functions.append({"lineno": node.lineno, "name": node.name})
Esempio n. 5
0
 def visit_Constant(self,
                    node: ast.Constant,
                    id_: Optional[int] = None) -> None:
     id_ = id_ or id(node)
     if not isinstance(node.value, (str, bytes)):
         return
     try:
         parent = first_occurrence(node, ast.FunctionDef)
     except AttributeError:
         with contextlib.suppress(SyntaxError):
             self.visit(ast.parse(node.value, mode="eval"))
     else:
         is_annasign_and_arg = any(
             type_parent in {ast.AnnAssign, ast.arg}
             for type_parent in map(type, get_parents(node)))
         if (parent and id(parent.returns) == id_) or is_annasign_and_arg:
             with contextlib.suppress(SyntaxError):
                 self.visit(ast.parse(node.value, mode="eval"))
Esempio n. 6
0
 def visit_CFN(self, node: C.CFNT) -> None:
     if not first_occurrence(node, C.DefTuple):
         self.suggestions_nodes.append(node)
Esempio n. 7
0
 def visit_Name(self, node: ast.Name) -> None:
     if not first_occurrence(node, ast.Attribute):
         self.names.append(Name(lineno=node.lineno, name=node.id))