python:S5708 does not understand abstracted tuples

This is a valid use case:

exceptions = (ZeroDivisionError, OverflowError)
try:
  foo = 1/0
except exceptions:
  foo = 0

Sonar flags this with python:S5708.

The reason we might want to put the tuple of exceptions in a variable is that we could have multiple try/except blocks catching the same error classes or simply as a way to make the code more readable without splitting the except line.

Hi @sodul,

Thank you for reporting this false positive.
I created the following ticket to keep track of it: https://jira.sonarsource.com/browse/SONARPY-713

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.