Skip to content

Concerning assert (S101) example and the change of > #6984

@Anselmoo

Description

@Anselmoo

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.

/// ## Example
/// ```python
/// assert x > 0, "Expected positive value."
/// ```
///
/// Use instead:
/// ```python
/// if x <= 0:
/// raise ValueError("Expected positive value.")
/// ```

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions