@@ -567,7 +567,9 @@ def leaves(exc):
567567 self .assertIs (eg .__cause__ , part .__cause__ )
568568 self .assertIs (eg .__context__ , part .__context__ )
569569 self .assertIs (eg .__traceback__ , part .__traceback__ )
570- self .assertIs (eg .__note__ , part .__note__ )
570+ self .assertEqual (
571+ getattr (eg , '__notes__' , None ),
572+ getattr (part , '__notes__' , None ))
571573
572574 def tbs_for_leaf (leaf , eg ):
573575 for e , tbs in leaf_generator (eg ):
@@ -632,7 +634,7 @@ def level3(i):
632634 try :
633635 nested_group ()
634636 except ExceptionGroup as e :
635- e .__note__ = f"the note: { id (e )} "
637+ e .add_note ( f"the note: { id (e )} " )
636638 eg = e
637639
638640 eg_template = [
@@ -728,6 +730,35 @@ def exc(ex):
728730 self .assertMatchesTemplate (
729731 rest , ExceptionGroup , [ValueError (1 )])
730732
733+ def test_split_copies_notes (self ):
734+ # make sure each exception group after a split has its own __notes__ list
735+ eg = ExceptionGroup ("eg" , [ValueError (1 ), TypeError (2 )])
736+ eg .add_note ("note1" )
737+ eg .add_note ("note2" )
738+ orig_notes = list (eg .__notes__ )
739+ match , rest = eg .split (TypeError )
740+ self .assertEqual (eg .__notes__ , orig_notes )
741+ self .assertEqual (match .__notes__ , orig_notes )
742+ self .assertEqual (rest .__notes__ , orig_notes )
743+ self .assertIsNot (eg .__notes__ , match .__notes__ )
744+ self .assertIsNot (eg .__notes__ , rest .__notes__ )
745+ self .assertIsNot (match .__notes__ , rest .__notes__ )
746+ eg .add_note ("eg" )
747+ match .add_note ("match" )
748+ rest .add_note ("rest" )
749+ self .assertEqual (eg .__notes__ , orig_notes + ["eg" ])
750+ self .assertEqual (match .__notes__ , orig_notes + ["match" ])
751+ self .assertEqual (rest .__notes__ , orig_notes + ["rest" ])
752+
753+ def test_split_does_not_copy_non_sequence_notes (self ):
754+ # __notes__ should be a sequence, which is shallow copied.
755+ # If it is not a sequence, the split parts don't get any notes.
756+ eg = ExceptionGroup ("eg" , [ValueError (1 ), TypeError (2 )])
757+ eg .__notes__ = 123
758+ match , rest = eg .split (TypeError )
759+ self .assertFalse (hasattr (match , '__notes__' ))
760+ self .assertFalse (hasattr (rest , '__notes__' ))
761+
731762
732763class NestedExceptionGroupSubclassSplitTest (ExceptionGroupSplitTestBase ):
733764
0 commit comments