Uploaded image for project: 'SonarPython'
  1. SonarPython
  2. SONARPY-680

S5797 should detect when a variable will always have the same mutable value

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Rules
    • Labels:
      None

      Description

      Currently the rule only supports immutable types when variables are used as conditions. This rule should also cover cases where the variable is set to a dict, set or list which are never modified.

      def mutable_captured(a, b):
          b_list = []
          for i in range(a):
              b_list.append(i)
      
          if b_list:
              return b_list
      
          a_list = []
      
          for i in range(b):
              b_list.append(i)  # Typo. Should have been a_list
      
          if a_list:  # Noncompliant. a_list is only set to an empty list and never modified nor passed to a function
              return a_list
      

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated: