當前位置: 首頁>>代碼示例>>Python>>正文


Python ast.AsyncWith方法代碼示例

本文整理匯總了Python中ast.AsyncWith方法的典型用法代碼示例。如果您正苦於以下問題:Python ast.AsyncWith方法的具體用法?Python ast.AsyncWith怎麽用?Python ast.AsyncWith使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ast的用法示例。


在下文中一共展示了ast.AsyncWith方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: with_stmt_rewrite

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import AsyncWith [as 別名]
def with_stmt_rewrite(mark, items, body, is_async=False):
    ty = ast.AsyncWith if is_async else ast.With
    return ty(items, body, **loc @ mark) 
開發者ID:Xython,項目名稱:YAPyPy,代碼行數:5,代碼來源:helper.py

示例2: insert_returns

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import AsyncWith [as 別名]
def insert_returns(body: List[ast.AST]) -> None:
    if isinstance(body[-1], ast.Expr):
        body[-1] = ast.Return(body[-1].value)
        ast.fix_missing_locations(body[-1])
    elif isinstance(body[-1], ast.If):
        insert_returns(body[-1].body)
        insert_returns(body[-1].orelse)
    elif isinstance(body[-1], (ast.With, ast.AsyncWith)):
        insert_returns(body[-1].body) 
開發者ID:tulir,項目名稱:mautrix-python,代碼行數:11,代碼來源:manhole.py

示例3: test_py35_node_types

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import AsyncWith [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_AsyncWith

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import AsyncWith [as 別名]
def visit_AsyncWith(self, node):
            new_node = gast.AsyncWith(
                self._visit(node.items),
                self._visit(node.body),
                None,  # type_comment
            )
            gast.copy_location(new_node, node)
            return new_node 
開發者ID:serge-sans-paille,項目名稱:gast,代碼行數:10,代碼來源:ast3.py

示例5: visit_With_3

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import AsyncWith [as 別名]
def visit_With_3(self, node):
    if hasattr(ast, 'AsyncWith') and isinstance(node, ast.AsyncWith):
      self.attr(node, 'with', ['async', self.ws, 'with', self.ws],
                default='async with ')
    else:
      self.attr(node, 'with', ['with', self.ws], default='with ')

    for i, withitem in enumerate(node.items):
      self.visit(withitem)
      if i != len(node.items) - 1:
        self.token(',')

    self.attr(node, 'with_body_open', [':', self.ws_oneline], default=':\n')
    for stmt in self.indented(node, 'body'):
      self.visit(stmt) 
開發者ID:google,項目名稱:pasta,代碼行數:17,代碼來源:annotate.py

示例6: fix_async_offset

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import AsyncWith [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.AsyncWith方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。