-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Summary
Rule B904 has docs which I find to be misleading. In the docs, they claim:
When raising an exception from within an except clause, always include a from clause to facilitate exception chaining. If the exception is not chained, it will be difficult to trace the exception back to its root cause.
But actually, exceptions get implicitly chained by default if there's no from clause. So this rule never helps facilitate chaining: it can only either A) reduce chaining, by encouraging people to specify from None, or B) just make the default chaining which was already happening more explicit.
I prefer to chain exceptions wherever possible for the reason indicated: I want to have the most possible context to be able to trace errors to their root cause. And having this rule active just creates needless boilerplate to capture what the default behaviour already would have done. If the docs were more accurate about this, I think it would be clearer that this is a rule which should be deselected for most people (IMO).
There's an argument that explicit chaining produces a slightly nicer message in the traceback than implicit chaining (The above exception was the direct cause of the following exception vs During handling of the above exception, another exception occurred). But if that small difference is the whole reason for this rule's existence, I think that is a lot harder to justify all the boilerplate created as a result of applying this rule and I think the docs could be more clear about the limited benefit.
Thanks, Shawn