The only two possible types for an except's expression are a class deriving from BaseException, or a tuple composed of
such classes.
This rule raises an issue when the expression used in an except block is a boolean expression of exceptions. The result of such
expression is a single exception class, which is valid but not what the developer intended.
try:
raise TypeError()
except ValueError or TypeError: # Noncompliant
print("Catching only ValueError")
except ValueError and TypeError: # Noncompliant
print("catching only TypeError")
except (ValueError or TypeError) as exception: # Noncompliant
print("Catching only ValueError")
foo = ValueError or TypeError # foo == ValueError
foo = ValueError and TypeError # foo == TypeError
try:
raise TypeError()
except (ValueError, TypeError) as exception:
print("Catching all exceptions")
try statement