Skip to content
Sarj Code Standards

no-mutating-input-with-result

Separate input attribute mutation from functions that return a result.

Why

Returning an operation result can hide writes to a request object retained by the caller. Reusing that input then observes state changed by an earlier call.

Fix

Build and return a replacement input before sending it, or expose a deliberate in-place command returning None. Preserve response values and input contracts; do not discard the result to silence the rule.

Examples

Before — flagged Sending a generated request changes the caller's request
api.py
from attrs import define
@define
class Request:
expected_version: int
def send_update(body: Request) -> Response:
body.expected_version = 2
return send(body)
After — preferred Send a replacement and keep the input unchanged
api.py
from attrs import define, evolve
@define
class Request:
expected_version: int
def send_update(body: Request) -> Response:
updated = evolve(body, expected_version=2)
return send(updated)