当前位置: 首页>>代码示例>>Python>>正文


Python ast.Pass方法代码示例

本文整理汇总了Python中ast.Pass方法的典型用法代码示例。如果您正苦于以下问题:Python ast.Pass方法的具体用法?Python ast.Pass怎么用?Python ast.Pass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ast的用法示例。


在下文中一共展示了ast.Pass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __exit_scope

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Pass [as 别名]
def __exit_scope(self) -> ast.stmt:
        """Create the appropriate scope exiting statement.

        The documentation only shows one level and always uses
        'return False' in examples.

        'raise AltFalse()' within a try.
        'break' within a loop.
        'return False' otherwise.
        """
        if self.in_optional:
            return ast.Pass()
        if self.in_try:
            return ast.Raise(
                ast.Call(ast.Name('AltFalse', ast.Load()), [], [], None, None),
                None)
        if self.in_loop:
            return ast.Break()
        return ast.Return(ast.Name('False', ast.Load()))

    #TODO(bps): find a better name to describe what this does 
开发者ID:LionelAuroux,项目名称:pyrser,代码行数:23,代码来源:topython.py

示例2: visit_Rep0N

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Pass [as 别名]
def visit_Rep0N(self, node: parsing.Rep0N) -> [ast.stmt]:
        """Generates python code for a clause repeated 0 or more times.

        #If all clauses can be inlined
        while clause:
            pass

        while True:
            <code for the clause>
        """
        cl_ast = self.visit(node.pt)
        if isinstance(cl_ast, ast.expr):
            return [ast.While(cl_ast, [ast.Pass()], [])]
        self.in_loop += 1
        clause = self._clause(self.visit(node.pt))
        self.in_loop -= 1
        return [ast.While(ast.Name('True', ast.Load()), clause, [])] 
开发者ID:LionelAuroux,项目名称:pyrser,代码行数:19,代码来源:topython.py

示例3: test_classdef

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Pass [as 别名]
def test_classdef(self):
        def cls(bases=None, keywords=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,
                                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(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") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:test_ast.py

示例4: test_try

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Pass [as 别名]
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") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_ast.py

示例5: test_classdef

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Pass [as 别名]
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") 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:27,代码来源:test_ast.py

示例6: onelinerize

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Pass [as 别名]
def onelinerize(original):
    # original :: string
    # :: string
    t = ast.parse(original)
    table = symtable.symtable(original, '<string>', 'exec')

    original = original.strip()

    # If there's only one line anyways, be lazy
    if len(original.splitlines()) == 1 and \
       len(t.body) == 1 and \
       type(t.body[0]) in (ast.Delete, ast.Assign, ast.AugAssign, ast.Print,
                           ast.Raise, ast.Assert, ast.Import, ast.ImportFrom,
                           ast.Exec, ast.Global, ast.Expr, ast.Pass):
        return original

    return get_init_code(t, table) 
开发者ID:csvoss,项目名称:onelinerizer,代码行数:19,代码来源:onelinerizer.py

示例7: visit

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Pass [as 别名]
def visit(self, node):
        super().visit(node)
        if self.last_node is not None:
            fake_node = ast.Pass(lineno=len(self.lines), col_offset=len(self.lines[-1]))
            self.generic_visit(fake_node) 
开发者ID:HPAC,项目名称:matchpy,代码行数:7,代码来源:utils.py

示例8: visit_Alt

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Pass [as 别名]
def visit_Alt(self, node: parsing.Alt) -> [ast.stmt]:
        """Generates python code for alternatives.

        try:
            try:
                <code for clause>  #raise AltFalse when alternative is False
                raise AltTrue()
            except AltFalse:
                pass
            return False
        except AltTrue:
            pass
        """
        clauses = [self.visit(clause) for clause in node.ptlist]
        for clause in clauses:
            if not isinstance(clause, ast.expr):
                break
        else:
            return ast.BoolOp(ast.Or(), clauses)
        res = ast.Try([], [ast.ExceptHandler(
            ast.Name('AltTrue', ast.Load()), None, [ast.Pass()])], [], [])
        alt_true = [ast.Raise(ast.Call(
            ast.Name('AltTrue', ast.Load()), [], [], None, None), None)]
        alt_false = [ast.ExceptHandler(
            ast.Name('AltFalse', ast.Load()), None, [ast.Pass()])]
        self.in_try += 1
        for clause in node.ptlist:
            res.body.append(
                ast.Try(self._clause(self.visit(clause)) + alt_true,
                        alt_false, [], []))
        self.in_try -= 1
        res.body.append(self.__exit_scope())
        return [res] 
开发者ID:LionelAuroux,项目名称:pyrser,代码行数:35,代码来源:topython.py

示例9: visit_Continue

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Pass [as 别名]
def visit_Continue(self, cont):
        """

        >>> self = FirstPassForSimple('foo')
        >>> code = 'continue'
        >>> module = ast.parse(code)
        >>> cont, = module.body

        """
        return ast.Pass() 
开发者ID:ebanner,项目名称:pynt,代码行数:12,代码来源:node_transformers.py

示例10: visit_Break

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Pass [as 别名]
def visit_Break(self, broken):
        """

        >>> self = FirstPassForSimple('foo')
        >>> code = 'break'
        >>> module = ast.parse(code)
        >>> broken, = module.body

        """
        return ast.Pass() 
开发者ID:ebanner,项目名称:pynt,代码行数:12,代码来源:node_transformers.py

示例11: visit_For

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Pass [as 别名]
def visit_For(self, loop_):
        """
        >>> self = FirstPassFor(buffer='foo')
        >>> code = '''
        ...
        ... for i in range(5):
        ...     for j in range(5):
        ...         k = i + j
        ...         print(k)
        ...
        ... '''
        >>> tree = ast.parse(code)
        >>> loop_, = tree.body

        """
        loop = self.generic_visit(loop_)
        var = ast.Name(id=__random_string__(), ctx=ast.Store())
        assign = ast.Assign(targets=[var], value=ast.Call(func=ast.Name(id='iter', ctx=ast.Load()), args=[loop.iter], keywords=[]))
        first_pass = ast.Try(
            body=[ast.Assign(targets=[loop.target], value=ast.Call(func=ast.Name(id='next', ctx=ast.Load()), args=[ast.Name(id=var, ctx=ast.Load())], keywords=[]))],
            handlers=[ast.ExceptHandler(type=ast.Name(id='StopIteration', ctx=ast.Load()), name=None, body=[ast.Pass()])],
            orelse=loop.body,
            finalbody=[]
        )
        content = f'`for {astor.to_source(loop.target).strip()} in {astor.to_source(loop.iter).strip()} ...`'
        return [
            make_annotation(buffer=self.buffer, content=content, cell_type='2', lineno=loop.lineno),
            ast.Expr(loop.iter),
            assign,
            first_pass
        ] 
开发者ID:ebanner,项目名称:pynt,代码行数:33,代码来源:node_transformers.py

示例12: test_funcdef

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Pass [as 别名]
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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:15,代码来源:test_ast.py

示例13: test_for

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Pass [as 别名]
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") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_ast.py

示例14: test_while

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Pass [as 别名]
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") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_ast.py

示例15: test_if

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Pass [as 别名]
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") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_ast.py


注:本文中的ast.Pass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。