Skip to content

Python · maintainability

trailing-value-narration

python:trailing-value-narration

Trailing comment restates a literal value and its unit.

Code
SARJ051
Default
error
Fix
suggestion
Languages
python

Why

A unit encoded only in a comment can drift from the value and is unavailable to type checking.

Fix

Encode the unit in the name or value type, such as timeout_seconds or timedelta.

Before / after

Executed by this rule’s unit tests.

Before

Comment repeats the duration

settings.py · focus
STALE_TIME = 5 * 60 * 1000  # 5 minutes

After

Comment explains a policy

settings.py · focus
BACKOFF = 2 * 60  # doubles per attempt

Limits

  • Detection targets simple numeric assignments with a trailing comment that repeats the number and unit.
  • Approximate conversions, reasons, references, directives, bracketed values, and generated files are excluded.