@@ -58,18 +58,15 @@ def rebuild_exception_chain(chain: SerializedExceptionChain) -> BaseException:
5858 if not chain :
5959 raise ValueError ("Chain must contain at least one exception" )
6060
61- # Materialise each entry into a (BaseException, tb_dict) pair so the
62- # linking loop below stays uniform.
6361 resolved : list [tuple [BaseException , dict [str , Any ]]] = []
64-
6562 for entry in chain :
6663 if isinstance (entry , SerializedExceptionGroup ):
6764 # Restore tracebacks on every inner exception.
68- restored_inners : list [Exception ] = []
65+ restored_inners : list [BaseException ] = []
6966 for serialized_inner in entry .exceptions :
7067 inner_exc = serialized_inner .ex
7168 inner_exc .__traceback__ = get_traceback_from_dict (serialized_inner .tb_dict )
72- restored_inners .append (inner_exc ) # type: ignore[arg-type]
69+ restored_inners .append (inner_exc )
7370
7471 # Re-create the group with the restored inner exceptions so that
7572 # the group's own .exceptions tuple reflects the restored state.
@@ -78,7 +75,8 @@ def rebuild_exception_chain(chain: SerializedExceptionChain) -> BaseException:
7875 else :
7976 resolved .append ((entry .ex , entry .tb_dict ))
8077
81- # Re-link the chain (cause → effect) and restore top-level tracebacks.
78+ # Re-create the "exception chain" (of __cause__s) and restore top-level (non-inner Exception)
79+ # tracebacks
8280 for i , (exc , tb_dict ) in enumerate (resolved ):
8381 exc .__traceback__ = get_traceback_from_dict (tb_dict )
8482 exc .__cause__ = resolved [i + 1 ][0 ] if i < len (resolved ) - 1 else None
0 commit comments