-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationgood first issueGood for newcomersGood for newcomers
Description
When using the assertion assert(S101), changing from x > 0 to x <= 0 can be confusing because these statements might have different meanings.
x <= 0 checks if x is less than or equal to zero, while x > 0 checks if x is greater than zero.
For example, if x is -1, then x <= 0 is true, but x > 0 is false. On the other hand, if x is 1, then x <= 0 is false, but x > 0 is true.
ruff/crates/ruff/src/rules/flake8_bandit/rules/assert_used.rs
Lines 19 to 28 in 25c3748
| /// ## Example | |
| /// ```python | |
| /// assert x > 0, "Expected positive value." | |
| /// ``` | |
| /// | |
| /// Use instead: | |
| /// ```python | |
| /// if x <= 0: | |
| /// raise ValueError("Expected positive value.") | |
| /// ``` |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationgood first issueGood for newcomersGood for newcomers