overlapping-except / W0714#

Message emitted:

Overlapping exceptions (%s)

Description:

Used when exceptions in handler overlap or are identical

Problematic code:

def divide_x_by_y(x: float, y: float):
    try:
        print(x / y)
    except (ArithmeticError, FloatingPointError) as e:  # [overlapping-except]
        print(f"There was an issue: {e}")

Correct code:

def divide_x_by_y(x: float, y: float):
    try:
        print(x / y)
    except FloatingPointError as e:
        print(f"There was a FloatingPointError: {e}")
    except ArithmeticError as e:
        # FloatingPointError  were already caught at this point
        print(f"There was an OverflowError or a ZeroDivisionError: {e}")

# Or:

def divide_x_by_y(x: float, y: float):
    try:
        print(x / y)
    except ArithmeticError as e:
        print(f"There was an OverflowError, a ZeroDivisionError or a FloatingPointError: {e}")

Related links:

Note

This message is emitted by the optional 'overlap-except' checker which requires the pylint.extensions.overlapping_exceptions plugin to be loaded.

Created by the overlap-except checker.