On Wed, Jun 16, 2021 at 11:45 AM Steven D'Aprano steve@pearwood.info wrote:
On Wed, Jun 16, 2021 at 10:56:12AM +1000, Chris Angelico wrote:
Dangerous idea - my first interpretation of that syntax was that it would be equivalent to "except ValueError: pass", which would be very confusing (it's subtly different in your example with return, and drastically different in other cases).
Aside from the difference in chained exceptions (the exception cause or context, I forget which is which, will be different) surely it is the same as `except ValueError: pass`?
TBH I thought that difference was so minor that it wasn't even worth mentioning.
That's the subtle difference. The drastic difference is that, if you ever change one of the cases (deliberately or accidentally) so it doesn't have the return, it'll daisychain - but only when that one gets hit.
But logically, there is a significant difference between putting code inside the except block, and having "except X: pass" and then putting code after. Code should be written the way it's meant to be, not the way that happens to work.
ChrisA