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


Python ast.AsyncFor方法代码示例

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


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

示例1: visit_For

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFor [as 别名]
def visit_For(self, node):
    if hasattr(ast, 'AsyncFor') and isinstance(node, ast.AsyncFor):
      self.attr(node, 'for_keyword', ['async', self.ws, 'for', self.ws],
                default='async for ')
    else:
      self.attr(node, 'for_keyword', ['for', self.ws], default='for ')
    self.visit(node.target)
    self.attr(node, 'for_in', [self.ws, 'in', self.ws], default=' in ')
    self.visit(node.iter)
    self.attr(node, 'open_block', [self.ws, ':', self.ws_oneline],
              default=':\n')
    for stmt in self.indented(node, 'body'):
        self.visit(stmt)

    if node.orelse:
      self.attr(node, 'else', [self.ws, 'else', self.ws, ':', self.ws_oneline],
                default=self._indent + 'else:\n')

      for stmt in self.indented(node, 'orelse'):
        self.visit(stmt) 
开发者ID:google,项目名称:pasta,代码行数:22,代码来源:annotate.py

示例2: for_stmt_rewrite

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFor [as 别名]
def for_stmt_rewrite(target, iter, body, orelse, is_async=False):
    orelse = orelse or []
    as_store(target)
    ty = ast.AsyncFor if is_async else ast.For
    return ty(target, iter, body, orelse) 
开发者ID:Xython,项目名称:YAPyPy,代码行数:7,代码来源:helper.py

示例3: test_py35_node_types

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFor [as 别名]
def test_py35_node_types(self):
        """
        Test that the PEP 492 node types are collected
        """
        visitor = self._run_visitor(
            """\
async def f():  # async def
    async for x in y:  pass  # async for
    async with a as b: pass  # async with
"""
        )
        self.assertEqual(visitor.typeable_lines, [1, 2, 3])
        self.assertIsInstance(visitor.typeable_nodes[1], ast.AsyncFunctionDef)
        self.assertIsInstance(visitor.typeable_nodes[2], ast.AsyncFor)
        self.assertIsInstance(visitor.typeable_nodes[3], ast.AsyncWith) 
开发者ID:PyCQA,项目名称:pyflakes,代码行数:17,代码来源:test_checker.py

示例4: visit_AsyncFor

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFor [as 别名]
def visit_AsyncFor(self, node):
            new_node = gast.AsyncFor(
                self._visit(node.target),
                self._visit(node.iter),
                self._visit(node.body),
                self._visit(node.orelse),
                None,  # type_comment
            )
            gast.copy_location(new_node, node)
            return new_node 
开发者ID:serge-sans-paille,项目名称:gast,代码行数:12,代码来源:ast3.py

示例5: fix_async_offset

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFor [as 别名]
def fix_async_offset(tree: ast.AST) -> ast.AST:
    """
    Fixes ``col_offest`` values for async nodes.

    This is a temporary check for async-based expressions, because offset
    for them isn't calculated properly. We can calculate right version
    of offset with subscripting ``6`` (length of "async " part).

    Affected ``python`` versions:

    - all versions below ``python3.6.7``

    Read more:
        https://bugs.python.org/issue29205
        https://github.com/wemake-services/wemake-python-styleguide/issues/282

    """
    nodes_to_fix = (
        ast.AsyncFor,
        ast.AsyncWith,
        ast.AsyncFunctionDef,
    )
    for node in ast.walk(tree):
        if isinstance(node, nodes_to_fix):
            error = 6 if node.col_offset % 4 else 0
            node.col_offset = node.col_offset - error
    return tree 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:29,代码来源:bugfixes.py


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