Skip to content
Sarj Code Standards

inline-single-use-local

Inline a local that only feeds the immediately following statement.

Why

A one-line temporary that is read only by the next statement adds a name, a line and a reader indirection without carrying state forward. Writing the expression at its single use keeps the data flow local; binding it with := at its first argument keeps one call self-contained when that call reads the value more than once.

Fix

Replace value = compute(); consume(value) with consume(compute()). When the next call reads the value up to three times, bind it at its first argument: Record(id=(record_id := new_id()), path=f'{record_id}.wav'). Keep the separate statement when the name is an intentional debugging boundary or the inlined call would stop reading clearly.

Examples

Before — flagged A temporary only feeds the next call
service.py
async def store(objects, path, audio):
payload = encode(audio)
await objects.upload(path=path, data=payload)
After — preferred The expression is written at its single use
service.py
async def store(objects, path, audio):
await objects.upload(path=path, data=encode(audio))