Ejemplo n.º 1
0
    def visit_Subscript(self, node):
        if not isinstance(node.ctx, _ast.Load) or not isinstance(node.slice, _ast.Index):
            return ASTTransformer.visit_Subscript(self, node)

        func = _new(_ast.Name, "_lookup_item", _ast.Load())
        args = [self.visit(node.value), _new(_ast.Tuple, (self.visit(node.slice.value),), _ast.Load())]
        return _new(_ast.Call, func, args, [])
Ejemplo n.º 2
0
    def visit_Subscript(self, node):
        if not isinstance(node.ctx, _ast.Load) or \
                not isinstance(node.slice, _ast.Index):
            return ASTTransformer.visit_Subscript(self, node)

        func = _new(_ast.Name, '_lookup_item', _ast.Load())
        args = [
            self.visit(node.value),
            _new(_ast.Tuple, (self.visit(node.slice.value), ), _ast.Load())
        ]
        return _new(_ast.Call, func, args, [])
Ejemplo n.º 3
0
    def visit_Subscript(self, node):
        if not isinstance(node.ctx, _ast.Load) or \
                not isinstance(node.slice, (_ast.Index, _ast_Constant, _ast.Name, _ast.Call)):
            return ASTTransformer.visit_Subscript(self, node)

        # Before Python 3.9 "foo[key]" wrapped the load of "key" in
        # "ast.Index(ast.Name(...))"
        if isinstance(node.slice, (_ast.Name, _ast.Call)):
            slice_value = node.slice
        else:
            slice_value = node.slice.value

        func = _new(_ast.Name, '_lookup_item', _ast.Load())
        args = [
            self.visit(node.value),
            _new(_ast.Tuple, (self.visit(slice_value), ), _ast.Load())
        ]
        return _new(_ast.Call, func, args, [])