This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author cool-RR
Recipients cool-RR
Date 2021-01-22.13:52:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I saw this line of code today:

I was about to tell this guy that his code is bad since the part after the `from` should be a specific exception, not just an exception class. I thought I should double-check myself first. Lo and behold: 

$ cat
def f():
    raise TypeError

except TypeError:
    raise ValueError from TypeError

$ python

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "", line 7, in <module>
    raise ValueError from TypeError

The line doesn't fail, but it silently trims away the stacktrace of the previous exception. (Normally the stacktrace would include what's inside the `f` function.)

I'm not sure whether this is intended behavior or not. The documentation does say "the second expression must be another exception class or instance" but (a) it's not clear what the use case is when it's a class and (b) I doubt that the person who wrote the code above, and any other person who writes such code, would be aware that their traceback got snipped until it's too late and they're stuck with a bug report with incomplete information.
Date User Action Args
2021-01-22 13:52:41cool-RRsetrecipients: + cool-RR
2021-01-22 13:52:41cool-RRsetmessageid: <>
2021-01-22 13:52:41cool-RRlinkissue43002 messages
2021-01-22 13:52:40cool-RRcreate