Details

    • Type: Language-Specification
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Impact:
      Unknown 'null' severity
    • Likelihood:
      Unknown 'null' severity

      Description

      The length of a collection is always greater than or equal to zero. So testing that a length is greater than or equal to zero doesn't make sense, since the result is always true. Similarly testing that it is less than zero will always return false. Perhaps the intent was to check the non-emptiness of the collection instead.

      Noncompliant Code Example

      mylist = []
      if len(myList) >= 0:  # Noncompliant
          pass
      
      if len(myList) < 0:  # Noncompliant
          pass
      

      Compliant Solution

      mylist = []
      if len(myList) >= 42:
          pass
      
      if len(myList) == 0:
          pass
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            nicolas.harraudeau Nicolas Harraudeau (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: