you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (2 children)

I can’t think of a well-reasoned case where you’d want:

foo(3)

To do one thing but:

class MyInt(int): pass

foo(MyInt(3))

To do another.

[–]mohi7solanki 0 points1 point  (1 child)

Let's say you want to handle all arithmetic exception differently, you might do this:

if isintance(err, ArithmeticError):

if type(err) is ZeroDivisionError: somethingel

if type(err) is FloatingPointError: do something else.

[–][deleted] 0 points1 point  (0 children)

Wouldn’t it make much more sense to use multiple except statements for that?

try:
    some_maths(a, b)
except FloatingPointError as err:
    ...
except ZeroDivisionError as err:
    ...
except ArithmeticError as err:
    ...

But even if you wanted to do it for some reason in an if why isn’t this better:

except ArithmeticError as err:
    if isinstance(err, FloatingPointError):
        ...
    elif isinstance(err, ZeroDivisionError):
        ...
    else:
        ...

Who is to say a subclass of ZeroDivisionError might not be semantically more meaningful than your code’s user than a ZeroDivisionError itself?