Skip to content

Misleading descriptions for raise-from exception chaining rules (B904 and TRY200) #8736

@theemathas

Description

@theemathas

In my understanding, the description pages for rules B904 and TRY200 say (paraphrased): "Re-raising an exception (i.e., catching an exception and then raising a different exception) without specifying a cause with the from keyword will make the raised exception not be chained, which means we won't have the full stack trace information."

This is incorrect. As per the official documentation, if an exception is re-raised without explicit chaining, it will be implicitly chained with the caught exception. Therefore, a re-raised exception without explicit chaining (which the linter rule says is bad) has similar behavior as explicit chaining (which the linter rule recommends). The main difference seems to be a slight difference in the wording of the stack trace. This behavior was not as well-documented in previous python versions, but it has been like this since at least version 3.5.9, if not older.

Side note: the fact that these two lint rules are duplicates is a known issue as per #2186

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions