Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:
It is intended behaviour. `raise ... from` is a general mechanism that you can call anywhere, it is not just limited to raising from the previous exception. It is designed for explicitly setting the chained exception to some arbitrary exception. See the PEP: https://www.python.org/dev/peps/pep-3134/#explicit-exception-chaining >>> raise ValueError('bad value') from IndexError('bad index') IndexError: bad index The above exception was the direct cause of the following exception: Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: bad value If you wish to chain from the current exception, you have to chain from the current exception, and not create a new one. This is not an interpreter bug, it's working fine. Your first instinct was correct: your colleague had written "bad code" and his intention was probably to raise from the exception he had just caught. Or just don't do anything. A `raise exception` inside an except block will be automatically chained with the current exception unless you explicitly disable it with `raise exception from None`. ---------- nosy: +steven.daprano resolution: -> not a bug stage: -> resolved status: open -> closed _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue43002> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com