TracebackException checks for loops between exceptions to prevent an
infinite traceback. It does this by putting the already-seen exception
into a set. This means that unhashable exception objects will cause an
error - an error that itself can likely not be printed because of the
presence of the unhashable exception in the chain.
In this case, we don't actually care about equality of the objects as
defined by the class designer; we want to check that we don't encounter
the self-same exception object, from a chain that is necessarily all in
memory at the same time. We can trivially do so by comparing identities
instead of equality.
An equivalent patch was merged in the CPython standard library.
TracebackException checks for loops between exceptions to prevent an infinite traceback. It does this by putting the already-seen exception into a set. This means that unhashable exception objects will cause an error - an error that itself can likely not be printed because of the presence of the unhashable exception in the chain.
In this case, we don't actually care about equality of the objects as defined by the class designer; we want to check that we don't encounter the self-same exception object, from a chain that is necessarily all in memory at the same time. We can trivially do so by comparing identities instead of equality.
An equivalent patch was merged in the CPython standard library.