我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用ast.withitem()。
def test_with(self): p = ast.Pass() self.stmt(ast.With([], [p]), "empty items on With") i = ast.withitem(ast.Num(3), None) self.stmt(ast.With([i], []), "empty body on With") i = ast.withitem(ast.Name("x", ast.Store()), None) self.stmt(ast.With([i], [p]), "must have Load context") i = ast.withitem(ast.Num(3), ast.Name("x", ast.Load())) self.stmt(ast.With([i], [p]), "must have Store context")