How to use the pyupgrade.Block.find function in pyupgrade

To help you get started, we’ve selected a few pyupgrade examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asottile / pyupgrade / pyupgrade.py View on Github external
def _find_if_else_block(tokens, i):
    # type: (List[Token], int) -> Tuple[Block, Block]
    if_block = Block.find(tokens, i)
    i = if_block.end
    while tokens[i].src != 'else':
        i += 1
    else_block = Block.find(tokens, i, trim_end=True)
    return if_block, else_block
github asottile / pyupgrade / pyupgrade.py View on Github external
def _replace_yield(tokens, i):  # type: (List[Token], int) -> None
    in_token = _find_token(tokens, i, 'in')
    colon = _find_block_start(tokens, i)
    block = Block.find(tokens, i, trim_end=True)
    container = tokens_to_src(tokens[in_token + 1:colon]).strip()
    tokens[i:block.end] = [Token('CODE', 'yield from {}\n'.format(container))]

pyupgrade

A tool to automatically upgrade syntax for newer versions.

MIT
Latest version published 17 days ago

Package Health Score

85 / 100
Full package analysis

Similar packages