Skip to content

Inline Immediately Yielded Variable

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Sourcery refactoring id: inline-immediately-yielded-variable

Section titled “Sourcery refactoring id: inline-immediately-yielded-variable”

Inline variable that is immediately yielded

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

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