Message385499
I saw this line of code today: https://github.com/hyperledger/sawtooth-sdk-python/commit/c27b962541c9ae68fd1e6dc691ddee883234f112#diff-eb008203eae2160c5e14c42e5fd2eee164709a93bf5136fa79cc256d4e46eaffR92
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 x.py
def f():
raise TypeError
try:
f()
except TypeError:
raise ValueError from TypeError
$ python x.py
TypeError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "x.py", line 7, in <module>
raise ValueError from TypeError
ValueError
```
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:41 | cool-RR | set | recipients:
+ cool-RR |
2021-01-22 13:52:41 | cool-RR | set | messageid: <1611323561.1.0.365445213907.issue43002@roundup.psfhosted.org> |
2021-01-22 13:52:41 | cool-RR | link | issue43002 messages |
2021-01-22 13:52:40 | cool-RR | create | |
|