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

Rule S3516 raises False Positives on methods which have an implicit return None.

    Details

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

      Description

      In python functions and methods return None by default when the end of the function is reached without encountering a return statement.
      We should not raise any issue if there is at least one path in a function leading to the end of this function and there is no return statement on this path.

      Example:

      def cannot_open_file(path):
          try:
              open(path)
          except FileNotFoundError as e:
              return True
          except IsADirectoryError as e:
              return True
          # no return, equivalent to "return None"
      

        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: