Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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))]