Skip to content

no-unused-copy-result

Use the replacement returned by a resolved copy API.

Why

Copy-on-write replacement APIs return another value rather than updating the original. Discarding their result can silently leave subsequent operations using unchanged data.

Fix

Assign, return, or otherwise consume the replacement. A copy hook intentionally exercised for its effects or exceptions can use a narrow suppression; do not automatically delete the call.

Examples

Before — flagged A standard-library replacement is ignored
app/records.py
from dataclasses import replace
def rename(record):
replace(record, name="new")
After — preferred Capture the standard-library replacement
app/records.py
from copy import replace
def rename(record):
result = replace(record, name="new")
return result
Before — flagged A replacement model is ignored
app/records.py
from pydantic import BaseModel
class Record(BaseModel):
name: str
def rename(record: Record):
record.model_copy(update={"name": "new"})
After — preferred Return the replacement to its caller
app/records.py
from pydantic import BaseModel
class Record(BaseModel):
name: str
def rename(record: Record):
return record.model_copy(update={"name": "new"})