Skip to content

no-delete-statement

Avoid del statements; prefer constructing an immutable replacement value.

Why

Deleting a name, attribute, or collection entry introduces lifetime or in-place mutation semantics that are harder to follow than explicit value construction.

Fix

Remove unused-value deletion markers. Rebuild collections with comprehensions, copies, or immutable value helpers such as dataclasses.replace. When an external API or deliberate lifetime boundary requires deletion, add an exact SARJ442 suppression on the statement and explain why.

Examples

Before — flagged Build a mapping without the removed entry
app/request.py
payload = dict(raw_payload)
del payload["secret"]
After — preferred Construct the desired mapping directly
app/request.py
payload = {key: value for key, value in raw_payload.items() if key != "secret"}

Formerly: no-deleted-only-override-parameter