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

False Positive on S905 when contextlib.supress is used

    Details

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

      Description

      astropy uses contextlib.supress as an equivalent to try...except when it wants to check if an expression raises an exception. This creates some False Positives for rule S905.

      from contextlib import suppress
      
      def supressExcept(a):
          with suppress(TypeError):
              a + ''  # False positive
              return a
      

      We should not raise any issue in contextlib.suppress blocks. There is no need to make complex conditions as we do for try...except. We didn't see any True Positive in a contextlib.suppress block up to now.

        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: