Skip to content

Commit ff4d92b

Browse files
SONARPY-950 S5708 (CaughtExceptionCheck) should not report on Ambiguous Symbols that might inherit from BaseException (#1031)
1 parent d021e2f commit ff4d92b

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

its/ruling/src/test/resources/expected/python-S5708.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

python-checks/src/main/java/org/sonar/python/checks/CaughtExceptionsCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ private static boolean inheritsFromBaseException(@Nullable Symbol symbol) {
8383
return true;
8484
}
8585
ClassSymbol classSymbol = (ClassSymbol) symbol;
86-
return classSymbol.isOrExtends(BASE_EXCEPTION) || classSymbol.hasUnresolvedTypeHierarchy();
86+
return classSymbol.canBeOrExtend(BASE_EXCEPTION);
8787
}
8888
}

python-checks/src/test/resources/checks/caughtExceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,9 @@ def foo():
5555
foo = 1/0
5656
except exceptions:
5757
foo = 0
58+
59+
import smtplib
60+
try:
61+
...
62+
except smtplib.SMTPServerDisconnected: # OK, SMTPServerDisconnected when Python version is unknown
63+
...

0 commit comments

Comments
 (0)