python类Pass()的实例源码

stmt.py 文件源码 项目:viper 作者: ethereum 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, stmt, context):
        self.stmt = stmt
        self.context = context
        self.stmt_table = {
            ast.Expr: self.expr,
            ast.Pass: self.parse_pass,
            ast.AnnAssign: self.ann_assign,
            ast.Assign: self.assign,
            ast.If: self.parse_if,
            ast.Call: self.call,
            ast.Assert: self.parse_assert,
            ast.For: self.parse_for,
            ast.AugAssign: self.aug_assign,
            ast.Break: self.parse_break,
            ast.Return: self.parse_return,
        }
        stmt_type = self.stmt.__class__
        if stmt_type in self.stmt_table:
            self.lll_node = self.stmt_table[stmt_type]()
        elif isinstance(stmt, ast.Name) and stmt.id == "throw":
            self.lll_node = LLLnode.from_list(['assert', 0], typ=None, pos=getpos(stmt))
        else:
            raise StructureException("Unsupported statement type", stmt)
test_ast.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_classdef(self):
        def cls(bases=None, keywords=None, starargs=None, kwargs=None,
                body=None, decorator_list=None):
            if bases is None:
                bases = []
            if keywords is None:
                keywords = []
            if body is None:
                body = [ast.Pass()]
            if decorator_list is None:
                decorator_list = []
            return ast.ClassDef("myclass", bases, keywords, starargs,
                                kwargs, body, decorator_list)
        self.stmt(cls(bases=[ast.Name("x", ast.Store())]),
                  "must have Load context")
        self.stmt(cls(keywords=[ast.keyword("x", ast.Name("x", ast.Store()))]),
                  "must have Load context")
        self.stmt(cls(starargs=ast.Name("x", ast.Store())),
                  "must have Load context")
        self.stmt(cls(kwargs=ast.Name("x", ast.Store())),
                  "must have Load context")
        self.stmt(cls(body=[]), "empty body on ClassDef")
        self.stmt(cls(body=[None]), "None disallowed")
        self.stmt(cls(decorator_list=[ast.Name("x", ast.Store())]),
                  "must have Load context")
test_ast.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_try(self):
        p = ast.Pass()
        t = ast.Try([], [], [], [p])
        self.stmt(t, "empty body on Try")
        t = ast.Try([ast.Expr(ast.Name("x", ast.Store()))], [], [], [p])
        self.stmt(t, "must have Load context")
        t = ast.Try([p], [], [], [])
        self.stmt(t, "Try has neither except handlers nor finalbody")
        t = ast.Try([p], [], [p], [p])
        self.stmt(t, "Try has orelse but no except handlers")
        t = ast.Try([p], [ast.ExceptHandler(None, "x", [])], [], [])
        self.stmt(t, "empty body on ExceptHandler")
        e = [ast.ExceptHandler(ast.Name("x", ast.Store()), "y", [p])]
        self.stmt(ast.Try([p], e, [], []), "must have Load context")
        e = [ast.ExceptHandler(None, "x", [p])]
        t = ast.Try([p], e, [ast.Expr(ast.Name("x", ast.Store()))], [p])
        self.stmt(t, "must have Load context")
        t = ast.Try([p], e, [p], [ast.Expr(ast.Name("x", ast.Store()))])
        self.stmt(t, "must have Load context")
test_ast.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_classdef(self):
        def cls(bases=None, keywords=None, starargs=None, kwargs=None,
                body=None, decorator_list=None):
            if bases is None:
                bases = []
            if keywords is None:
                keywords = []
            if body is None:
                body = [ast.Pass()]
            if decorator_list is None:
                decorator_list = []
            return ast.ClassDef("myclass", bases, keywords, starargs,
                                kwargs, body, decorator_list)
        self.stmt(cls(bases=[ast.Name("x", ast.Store())]),
                  "must have Load context")
        self.stmt(cls(keywords=[ast.keyword("x", ast.Name("x", ast.Store()))]),
                  "must have Load context")
        self.stmt(cls(starargs=ast.Name("x", ast.Store())),
                  "must have Load context")
        self.stmt(cls(kwargs=ast.Name("x", ast.Store())),
                  "must have Load context")
        self.stmt(cls(body=[]), "empty body on ClassDef")
        self.stmt(cls(body=[None]), "None disallowed")
        self.stmt(cls(decorator_list=[ast.Name("x", ast.Store())]),
                  "must have Load context")
test_ast.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_try(self):
        p = ast.Pass()
        t = ast.Try([], [], [], [p])
        self.stmt(t, "empty body on Try")
        t = ast.Try([ast.Expr(ast.Name("x", ast.Store()))], [], [], [p])
        self.stmt(t, "must have Load context")
        t = ast.Try([p], [], [], [])
        self.stmt(t, "Try has neither except handlers nor finalbody")
        t = ast.Try([p], [], [p], [p])
        self.stmt(t, "Try has orelse but no except handlers")
        t = ast.Try([p], [ast.ExceptHandler(None, "x", [])], [], [])
        self.stmt(t, "empty body on ExceptHandler")
        e = [ast.ExceptHandler(ast.Name("x", ast.Store()), "y", [p])]
        self.stmt(ast.Try([p], e, [], []), "must have Load context")
        e = [ast.ExceptHandler(None, "x", [p])]
        t = ast.Try([p], e, [ast.Expr(ast.Name("x", ast.Store()))], [p])
        self.stmt(t, "must have Load context")
        t = ast.Try([p], e, [p], [ast.Expr(ast.Name("x", ast.Store()))])
        self.stmt(t, "must have Load context")
pre_analysis.py 文件源码 项目:Typpete 作者: caterinaurban 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def add_init_if_not_existing(class_node):
    """Add a default empty __init__ function if it doesn't exist in the class node"""
    for stmt in class_node.body:
        if isinstance(stmt, ast.FunctionDef) and stmt.name == "__init__":
            return
    class_node.body.append(ast.FunctionDef(
        name="__init__",
        args=ast.arguments(
            args=[ast.arg(arg="self", annotation=None, lineno=class_node.lineno)],
            vararg=None,
            kwonlyargs=[],
            kw_defaults=[],
            kwarg=None,
            defaults=[]
        ),
        body=[ast.Pass()],
        decorator_list=[],
        returns=None,
        lineno=class_node.lineno
    ))
operators.py 文件源码 项目:mutpy 作者: mutpy 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def mutate_unpack(self, node):
        target = node.targets[0]
        value = node.value
        new_targets = []
        new_values = []
        for target_element, value_element in zip(target.elts, value.elts):
            if not self.is_overridden(node, getattr(target_element, 'id', None)):
                new_targets.append(target_element)
                new_values.append(value_element)
        if len(new_targets) == len(target.elts):
            raise MutationResign()
        if not new_targets:
            return ast.Pass()
        elif len(new_targets) == 1:
            node.targets = new_targets
            node.value = new_values[0]
            return node
        else:
            target.elts = new_targets
            value.elts = new_values
            return node
coverage.py 文件源码 项目:mutpy 作者: mutpy 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_coverable_nodes(cls):
        return {
            ast.Assert,
            ast.Assign,
            ast.AugAssign,
            ast.Break,
            ast.Continue,
            ast.Delete,
            ast.Expr,
            ast.Global,
            ast.Import,
            ast.ImportFrom,
            ast.Nonlocal,
            ast.Pass,
            ast.Raise,
            ast.Return,
            ast.FunctionDef,
            ast.ClassDef,
            ast.TryExcept,
            ast.TryFinally,
            ast.ExceptHandler,
            ast.If,
            ast.For,
            ast.While,
        }
coverage.py 文件源码 项目:mutpy 作者: mutpy 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_coverable_nodes(cls):
        return {
            ast.Assert,
            ast.Assign,
            ast.AugAssign,
            ast.Break,
            ast.Continue,
            ast.Delete,
            ast.Expr,
            ast.Global,
            ast.Import,
            ast.ImportFrom,
            ast.Nonlocal,
            ast.Pass,
            ast.Raise,
            ast.Return,
            ast.ClassDef,
            ast.FunctionDef,
            ast.Try,
            ast.ExceptHandler,
            ast.If,
            ast.For,
            ast.While,
        }
test_ast.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_classdef(self):
        def cls(bases=None, keywords=None, starargs=None, kwargs=None,
                body=None, decorator_list=None):
            if bases is None:
                bases = []
            if keywords is None:
                keywords = []
            if body is None:
                body = [ast.Pass()]
            if decorator_list is None:
                decorator_list = []
            return ast.ClassDef("myclass", bases, keywords, starargs,
                                kwargs, body, decorator_list)
        self.stmt(cls(bases=[ast.Name("x", ast.Store())]),
                  "must have Load context")
        self.stmt(cls(keywords=[ast.keyword("x", ast.Name("x", ast.Store()))]),
                  "must have Load context")
        self.stmt(cls(starargs=ast.Name("x", ast.Store())),
                  "must have Load context")
        self.stmt(cls(kwargs=ast.Name("x", ast.Store())),
                  "must have Load context")
        self.stmt(cls(body=[]), "empty body on ClassDef")
        self.stmt(cls(body=[None]), "None disallowed")
        self.stmt(cls(decorator_list=[ast.Name("x", ast.Store())]),
                  "must have Load context")
test_ast.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_try(self):
        p = ast.Pass()
        t = ast.Try([], [], [], [p])
        self.stmt(t, "empty body on Try")
        t = ast.Try([ast.Expr(ast.Name("x", ast.Store()))], [], [], [p])
        self.stmt(t, "must have Load context")
        t = ast.Try([p], [], [], [])
        self.stmt(t, "Try has neither except handlers nor finalbody")
        t = ast.Try([p], [], [p], [p])
        self.stmt(t, "Try has orelse but no except handlers")
        t = ast.Try([p], [ast.ExceptHandler(None, "x", [])], [], [])
        self.stmt(t, "empty body on ExceptHandler")
        e = [ast.ExceptHandler(ast.Name("x", ast.Store()), "y", [p])]
        self.stmt(ast.Try([p], e, [], []), "must have Load context")
        e = [ast.ExceptHandler(None, "x", [p])]
        t = ast.Try([p], e, [ast.Expr(ast.Name("x", ast.Store()))], [p])
        self.stmt(t, "must have Load context")
        t = ast.Try([p], e, [p], [ast.Expr(ast.Name("x", ast.Store()))])
        self.stmt(t, "must have Load context")
prune_cfg.py 文件源码 项目:peval 作者: fjarri 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def filter_block(node_list):
    """
    Remove no-op code (``pass``), or any code after
    an unconditional jump (``return``, ``break``, ``continue``, ``raise``).
    """
    if len(node_list) == 1:
        return node_list

    new_list = []
    for node in node_list:
        if type(node) == ast.Pass:
            continue
        new_list.append(node)
        if type(node) in (ast.Return, ast.Break, ast.Continue, ast.Raise):
            break
    if len(new_list) == len(node_list):
        return node_list
    else:
        return new_list
cfg_generator.py 文件源码 项目:Lyra 作者: caterinaurban 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _translate_body(self, body, types, allow_loose_in_edges=False, allow_loose_out_edges=False):
        cfg_factory = CFGFactory(self._id_gen)

        for child in body:
            if isinstance(child, (ast.AnnAssign, ast.Expr)):
                cfg_factory.add_stmts(self.visit(child, types))
            elif isinstance(child, ast.If):
                cfg_factory.complete_basic_block()
                if_cfg = self.visit(child, types)
                cfg_factory.append_cfg(if_cfg)
            elif isinstance(child, ast.While):
                cfg_factory.complete_basic_block()
                while_cfg = self.visit(child, types)
                cfg_factory.append_cfg(while_cfg)
            elif isinstance(child, ast.Break):
                cfg_factory.complete_basic_block()
                break_cfg = self.visit(child, types)
                cfg_factory.append_cfg(break_cfg)
            elif isinstance(child, ast.Continue):
                cfg_factory.complete_basic_block()
                cont_cfg = self.visit(child, types)
                cfg_factory.append_cfg(cont_cfg)
            elif isinstance(child, ast.Pass):
                if cfg_factory.incomplete_block():
                    pass
                else:
                    cfg_factory.append_cfg(_dummy_cfg(self._id_gen))
            else:
                raise NotImplementedError(f"The statement {str(type(child))} is not yet translatable to CFG!")
        cfg_factory.complete_basic_block()

        if not allow_loose_in_edges and cfg_factory.cfg and cfg_factory.cfg.loose_in_edges:
            cfg_factory.prepend_cfg(_dummy_cfg(self._id_gen))
        if not allow_loose_out_edges and cfg_factory.cfg and cfg_factory.cfg.loose_out_edges:
            cfg_factory.append_cfg(_dummy_cfg(self._id_gen))

        return cfg_factory.cfg
dead_code_elimination.py 文件源码 项目:opyum 作者: Amper 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def visit_If(self, node):
        node = self.generic_visit(node)
        if (node.orelse 
        and len(node.orelse) == 1 
        and isinstance(node.orelse[0], ast.Pass)
           ):
            node.orelse = []
        if (len(node.body) == 1
        and isinstance(node.body[0], ast.Pass)
           ):
            if node.orelse:
                node_test = ast.UnaryOp(op=ast.Not(), operand=node.test)
                if (len(node.orelse) == 1
                and isinstance(node.orelse[0], ast.If)
                   ):
                    node_test   = ast.BoolOp\
                                        ( op     = ast.And()
                                        , values = [node_test, node.orelse[0].test]
                                        )
                    node.test   = ast.copy_location(node_test, node.orelse[0].test)
                    node.body   = node.orelse[0].body
                    node.orelse = node.orelse[0].orelse
                else:
                    node.test   = ast.copy_location(node_test, node.test)
                    node.body   = node.orelse
                    node.orelse = []
            else:
                node = None
        return node
astTools.py 文件源码 项目:ITAP-django 作者: krivers 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def isStatement(a):
    """Determine whether the given node is a statement (vs an expression)"""
    return type(a) in [ ast.Module, ast.Interactive, ast.Expression, ast.Suite,
                        ast.FunctionDef, ast.ClassDef, ast.Return, ast.Delete,
                        ast.Assign, ast.AugAssign, ast.For, ast.While, 
                        ast.If, ast.With, ast.Raise, ast.Try, 
                        ast.Assert, ast.Import, ast.ImportFrom, ast.Global, 
                        ast.Expr, ast.Pass, ast.Break, ast.Continue ]
try_except_pass.py 文件源码 项目:bandit-ss 作者: zeroSteiner 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def try_except_pass(context, config):
    node = context.node
    if len(node.body) == 1:
        if (not config['check_typed_exception'] and
                node.type is not None and
                getattr(node.type, 'id', None) != 'Exception'):
            return

        if isinstance(node.body[0], ast.Pass):
            return bandit.Issue(
                severity=bandit.LOW,
                confidence=bandit.HIGH,
                text=("Try, Except, Pass detected.")
            )
test_ast.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_funcdef(self):
        a = ast.arguments([], None, None, [], None, None, [], [])
        f = ast.FunctionDef("x", a, [], [], None)
        self.stmt(f, "empty body on FunctionDef")
        f = ast.FunctionDef("x", a, [ast.Pass()], [ast.Name("x", ast.Store())],
                            None)
        self.stmt(f, "must have Load context")
        f = ast.FunctionDef("x", a, [ast.Pass()], [],
                            ast.Name("x", ast.Store()))
        self.stmt(f, "must have Load context")
        def fac(args):
            return ast.FunctionDef("x", args, [ast.Pass()], [], None)
        self._check_arguments(fac, self.stmt)
test_ast.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_for(self):
        x = ast.Name("x", ast.Store())
        y = ast.Name("y", ast.Load())
        p = ast.Pass()
        self.stmt(ast.For(x, y, [], []), "empty body on For")
        self.stmt(ast.For(ast.Name("x", ast.Load()), y, [p], []),
                  "must have Store context")
        self.stmt(ast.For(x, ast.Name("y", ast.Store()), [p], []),
                  "must have Load context")
        e = ast.Expr(ast.Name("x", ast.Store()))
        self.stmt(ast.For(x, y, [e], []), "must have Load context")
        self.stmt(ast.For(x, y, [p], [e]), "must have Load context")
test_ast.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_while(self):
        self.stmt(ast.While(ast.Num(3), [], []), "empty body on While")
        self.stmt(ast.While(ast.Name("x", ast.Store()), [ast.Pass()], []),
                  "must have Load context")
        self.stmt(ast.While(ast.Num(3), [ast.Pass()],
                             [ast.Expr(ast.Name("x", ast.Store()))]),
                             "must have Load context")
test_ast.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_if(self):
        self.stmt(ast.If(ast.Num(3), [], []), "empty body on If")
        i = ast.If(ast.Name("x", ast.Store()), [ast.Pass()], [])
        self.stmt(i, "must have Load context")
        i = ast.If(ast.Num(3), [ast.Expr(ast.Name("x", ast.Store()))], [])
        self.stmt(i, "must have Load context")
        i = ast.If(ast.Num(3), [ast.Pass()],
                   [ast.Expr(ast.Name("x", ast.Store()))])
        self.stmt(i, "must have Load context")
test_fatoptimizer.py 文件源码 项目:fatoptimizer 作者: vstinner 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_try_logger_empty_else(self):
        self.config.logger = io.StringIO()

        def get_logs():
            logger = self.config.logger
            logger.seek(0)
            return logger.readlines()

        self.check_optimize("""
            try:
                func1()
            except Exception:
                func2()
            else:
                pass
                pass
            finally:
                func3()
        """, """
            try:
                func1()
            except Exception:
                func2()
            finally:
                func3()
        """)

        self.assertEqual(get_logs(),
                         ['<string>:6: fatoptimizer: Remove dead code (empty else block in try/except): Pass()\n',
                          '<string>:7: fatoptimizer: Remove dead code (empty else block in try/except): Pass()\n'])
test_fatoptimizer.py 文件源码 项目:fatoptimizer 作者: vstinner 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_try_logger_empty_body(self):
        self.config.logger = io.StringIO()

        def get_logs():
            logger = self.config.logger
            logger.seek(0)
            return logger.readlines()

        self.check_optimize("""
            try:
                pass
            except Exception:
                func2()
            finally:
                func3()
        """, """
            func3()
        """)

        self.assertEqual(get_logs(),
                        ['<string>:2: fatoptimizer: Remove dead code '
                            '(empty try block): Pass()\n',
                         '<string>:3: fatoptimizer: Remove dead code '
                             "(empty try block): "
                             "ExceptHandler(type=Name(id='Exception', "
                             "ctx=Load()), name=None, "
                             "body=[Expr(value=Call(func=Name(id='(...)\n"])
test_fatoptimizer.py 文件源码 项目:fatoptimizer 作者: vstinner 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_replace_with_constant(self):
        # list => tuple
        self.check_optimize('for x in [1, 2, 3]: pass',
                            'for x in (1, 2, 3): pass')

        # set => frozenset
        self.check_optimize('for x in {1, 2, 3}: pass',
                            ast.For(target=ast.Name(id='x', ctx=ast.Store()),
                                    iter=ast.Constant(frozenset((1, 2, 3))),
                                    body=[ast.Pass()],
                                    orelse=[]))

        # don't optimize if items are not constants
        self.check_dont_optimize('for x in [1, x]: pass')
        self.check_dont_optimize('for x in {1, x}: pass')
dead_code.py 文件源码 项目:fatoptimizer 作者: vstinner 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def is_empty_body(node_list):
    if not node_list:
        return True
    return all(isinstance(node, ast.Pass) for node in node_list)
dead_code.py 文件源码 项目:fatoptimizer 作者: vstinner 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def _replace_node(self, node, node_list):
        if node_list:
            return node_list

        # FIXME: move this in NodeTransformer?
        new_node = ast.Pass()
        copy_lineno(node, new_node)
        return new_node
inline.py 文件源码 项目:fatoptimizer 作者: vstinner 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def visit_Call(self, node):
        if not self.config.inlining:
            return

        # FIXME: renaming variables to avoid clashes
        # or do something like:
        #   .saved_locals = locals()
        #   set params to args
        #   body of called function
        #   locals() = .saved_locals
        #   how to things that aren't just a return
        #   how to handle early return
        # FIXME: what guards are needed?
        # etc
        expansion = self.can_inline(node)
        if not expansion:
            return node
        funcdef = expansion.funcdef
        # Substitute the Call with the expression of the single return stmt
        # within the callee.
        # This assumes a single Return or Pass stmt
        stmt = funcdef.body[0]
        if isinstance(stmt, ast.Return):
            returned_expr = funcdef.body[0].value
            # Rename params/args
            v = RenameVisitor(node, funcdef, expansion.actual_pos_args)
            new_expr = v.visit(returned_expr)
        else:
            assert isinstance(stmt, ast.Pass)
            new_expr = self.new_constant(stmt, None)
        return new_expr
test_ast.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_funcdef(self):
        a = ast.arguments([], None, [], [], None, [])
        f = ast.FunctionDef("x", a, [], [], None)
        self.stmt(f, "empty body on FunctionDef")
        f = ast.FunctionDef("x", a, [ast.Pass()], [ast.Name("x", ast.Store())],
                            None)
        self.stmt(f, "must have Load context")
        f = ast.FunctionDef("x", a, [ast.Pass()], [],
                            ast.Name("x", ast.Store()))
        self.stmt(f, "must have Load context")
        def fac(args):
            return ast.FunctionDef("x", args, [ast.Pass()], [], None)
        self._check_arguments(fac, self.stmt)
test_ast.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_for(self):
        x = ast.Name("x", ast.Store())
        y = ast.Name("y", ast.Load())
        p = ast.Pass()
        self.stmt(ast.For(x, y, [], []), "empty body on For")
        self.stmt(ast.For(ast.Name("x", ast.Load()), y, [p], []),
                  "must have Store context")
        self.stmt(ast.For(x, ast.Name("y", ast.Store()), [p], []),
                  "must have Load context")
        e = ast.Expr(ast.Name("x", ast.Store()))
        self.stmt(ast.For(x, y, [e], []), "must have Load context")
        self.stmt(ast.For(x, y, [p], [e]), "must have Load context")
test_ast.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_while(self):
        self.stmt(ast.While(ast.Num(3), [], []), "empty body on While")
        self.stmt(ast.While(ast.Name("x", ast.Store()), [ast.Pass()], []),
                  "must have Load context")
        self.stmt(ast.While(ast.Num(3), [ast.Pass()],
                             [ast.Expr(ast.Name("x", ast.Store()))]),
                             "must have Load context")
test_ast.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def test_if(self):
        self.stmt(ast.If(ast.Num(3), [], []), "empty body on If")
        i = ast.If(ast.Name("x", ast.Store()), [ast.Pass()], [])
        self.stmt(i, "must have Load context")
        i = ast.If(ast.Num(3), [ast.Expr(ast.Name("x", ast.Store()))], [])
        self.stmt(i, "must have Load context")
        i = ast.If(ast.Num(3), [ast.Pass()],
                   [ast.Expr(ast.Name("x", ast.Store()))])
        self.stmt(i, "must have Load context")


问题


面经


文章

微信
公众号

扫码关注公众号