Skip to content

Inline Immediately Yielded Variable

Sourcery refactoring id: inline-immediately-yielded-variable

Description

Inline variable that is immediately yielded

Before

def f(a):
    b = a + 1
    yield b


def g(a):
    b = [1, 2, 3]
    yield from b

After

def f(a):
    yield a + 1


def g(a):
    yield from [1, 2, 3]

Explanation

Yielding the result directly shortens the code and makes it more readable.