Why this matters
Assertions can be disabled in production, meaning critical checks might not run. Use explicit validation with exceptions to ensure errors are handled properly.
Ensure that `assert` is not used for validating user input or critical checks. Assertions can be disabled in optimized mode (`python -O`). Recommend using explicit validation with `if` conditions and raising proper exceptions.
Assertions can be disabled in production, meaning critical checks might not run. Use explicit validation with exceptions to ensure errors are handled properly.
Side-by-side examples engineers can pattern-match during review.
assert x > 0, 'x must be positive'if x <= 0:
raise ValueError('x must be positive')assert x > 0, 'x must be positive'if x <= 0:
raise ValueError('x must be positive')From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.