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


Python ast.Module方法代码示例

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


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

示例1: run

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Module [as 别名]
def run(self, frame):
        expr = Interpretable(self.expr)
        expr.eval(frame)
        self.result = expr.result
        self.explanation = '... = ' + expr.explanation
        # fall-back-run the rest of the assignment
        ass = ast.Assign(self.nodes, ast.Name('__exprinfo_expr'))
        mod = ast.Module(None, ast.Stmt([ass]))
        mod.filename = '<run>'
        co = pycodegen.ModuleCodeGenerator(mod).getCode()
        try:
            frame.exec_(co, __exprinfo_expr=expr.result)
        except passthroughex:
            raise
        except:
            raise Failure(self) 
开发者ID:pytest-dev,项目名称:py,代码行数:18,代码来源:_assertionold.py

示例2: testMultipleLHS

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Module [as 别名]
def testMultipleLHS(self):
        """ Test multiple targets on the left hand side. """

        snippets = ['a, b = 1, 2',
                    '(a, b) = 1, 2',
                    '((a, b), c) = (1, 2), 3']

        for s in snippets:
            a = transformer.parse(s)
            self.assertIsInstance(a, ast.Module)
            child1 = a.getChildNodes()[0]
            self.assertIsInstance(child1, ast.Stmt)
            child2 = child1.getChildNodes()[0]
            self.assertIsInstance(child2, ast.Assign)

            # This actually tests the compiler, but it's a way to assure the ast
            # is correct
            c = compile(s, '<string>', 'single')
            vals = {}
            exec c in vals
            assert vals['a'] == 1
            assert vals['b'] == 2 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_transformer.py

示例3: CheckedEval

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Module [as 别名]
def CheckedEval(file_contents):
  """Return the eval of a gyp file.

  The gyp file is restricted to dictionaries and lists only, and
  repeated keys are not allowed.

  Note that this is slower than eval() is.
  """

  ast = compiler.parse(file_contents)
  assert isinstance(ast, Module)
  c1 = ast.getChildren()
  assert c1[0] is None
  assert isinstance(c1[1], Stmt)
  c2 = c1[1].getChildren()
  assert isinstance(c2[0], Discard)
  c3 = c2[0].getChildren()
  assert len(c3) == 1
  return CheckNode(c3[0], []) 
开发者ID:zhaoolee,项目名称:StarsAndClown,代码行数:21,代码来源:input.py

示例4: testMultipleLHS

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Module [as 别名]
def testMultipleLHS(self):
        """ Test multiple targets on the left hand side. """

        snippets = ['a, b = 1, 2',
                    '(a, b) = 1, 2',
                    '((a, b), c) = (1, 2), 3']

        for s in snippets:
            a = transformer.parse(s)
            assert isinstance(a, ast.Module)
            child1 = a.getChildNodes()[0]
            assert isinstance(child1, ast.Stmt)
            child2 = child1.getChildNodes()[0]
            assert isinstance(child2, ast.Assign)

            # This actually tests the compiler, but it's a way to assure the ast
            # is correct
            c = compile(s, '<string>', 'single')
            vals = {}
            exec c in vals
            assert vals['a'] == 1
            assert vals['b'] == 2 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:24,代码来源:test_transformer.py


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