You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The args attribute of the MyExceptionGroup instance will have three items -- code, msg, and exceptions. Now exceptions is the third item, not the second item, but ExceptionGroup.__init__() cannot know this.
Activity
serhiy-storchaka commentedon Aug 18, 2025
This is because
BaseException.__reduce__()returnsBaseException.argswhich is a tuple of the original arguments. And one of them is a mutable list.You can have issue with non-recursive ExceptionGroup:
I think there may be similar issues with other exceptions too.
The
BaseExceptionexception constructor is split on two parts,__new__()and__init__(), andargsis set in both of them.serhiy-storchaka commentedon Aug 18, 2025
We can change the
argsattribute so the second item is a tuple, but this will not work in general case, for ExceptionGroup subclasses. For example:The
argsattribute of the MyExceptionGroup instance will have three items --code,msg, andexceptions. Nowexceptionsis the third item, not the second item, butExceptionGroup.__init__()cannot know this.