示例#1
0
 def visit_Attribute(self, node: ast.Attribute) -> ast.Attribute:
     """
     Direct name.attribute references.
     """
     if isinstance(node.ctx, ast.Store):
         node.attr = self.add_placeholder(node.attr)
     if isinstance(node.ctx, ast.Load):
         node.attr = self.get_placeholder(node.attr)
     self.generic_visit(node)
     return node
示例#2
0
    def visit_Attribute(self, node: ast.Attribute):
        if type(node.value) == ast.Name:
            _id = node.value.id
            if _id == "self":
                node.attr = self.get_new_sym(node.attr)
            elif node.value.id not in self.excludes:
                node.value.id = self.get_new_sym(node.value.id)
        elif type(node.value) == ast.Attribute:
            if type(node.value.value) == ast.Name and node.value.value.id == "self":
                self.visit(node.value)
        elif type(node.value) == ast.Subscript:
            self.visit(node.value)

        return node
示例#3
0
    def visit_Attribute(self, node: ast.Attribute) -> Any:
        """
        Set a custom attribute on the current node.

        The custom attribute lets us read attribute names for `a.b.c` as `a.b.c`
        when we're handling the `c` node, which is important to match attributes to imports
        """
        with suppress(Exception):
            parent = getattr(node, ATTRIBUTE_PROPERTY)
            node.attr = f'{node.attr}.{parent}'
        node = self.set_child_node_attribute(node, ATTRIBUTE_PROPERTY,
                                             node.attr)
        self.generic_visit(node)
        return node
示例#4
0
 def visit_Attribute(self, node: ast.Attribute) -> ast.AST:
     node.attr = self._get_replacement_identifier(node.attr)
     return self.generic_visit(node)