@@ -2459,7 +2459,7 @@ fn check_except_star_type_valid(match_type: &PyObjectRef, vm: &VirtualMachine) -
24592459 // If it's a tuple, check each element
24602460 if let Ok ( tuple) = match_type. clone ( ) . downcast :: < PyTuple > ( ) {
24612461 for item in tuple. iter ( ) {
2462- check_one ( & item) ?;
2462+ check_one ( item) ?;
24632463 }
24642464 } else {
24652465 check_one ( match_type) ?;
@@ -2510,6 +2510,13 @@ pub fn exception_group_match(
25102510 // Check for partial match if it's an exception group
25112511 if exc_value. fast_isinstance ( vm. ctx . exceptions . base_exception_group ) {
25122512 let pair = vm. call_method ( exc_value, "split" , ( match_type. clone ( ) , ) ) ?;
2513+ if !pair. class ( ) . is ( vm. ctx . types . tuple_type ) {
2514+ return Err ( vm. new_type_error ( format ! (
2515+ "{}.split must return a tuple, not {}" ,
2516+ exc_value. class( ) . name( ) ,
2517+ pair. class( ) . name( )
2518+ ) ) ) ;
2519+ }
25132520 let pair_tuple: PyTupleRef = pair. try_into_value ( vm) ?;
25142521 if pair_tuple. len ( ) < 2 {
25152522 return Err ( vm. new_type_error ( format ! (
@@ -2528,7 +2535,7 @@ pub fn exception_group_match(
25282535}
25292536
25302537/// Prepare exception for reraise in except* block.
2531- /// Implements _PyExc_PrepReraiseStar from Objects/exceptions.c
2538+ /// Implements _PyExc_PrepReraiseStar
25322539pub fn prep_reraise_star ( orig : PyObjectRef , excs : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
25332540 use crate :: builtins:: PyList ;
25342541
@@ -2633,11 +2640,11 @@ fn collect_exception_group_leaf_ids(
26332640 }
26342641
26352642 // Recurse into exception group's exceptions
2636- if let Ok ( excs_attr) = exc. get_attr ( "exceptions" , vm) {
2637- if let Ok ( tuple) = excs_attr. downcast :: < PyTuple > ( ) {
2638- for e in tuple . iter ( ) {
2639- collect_exception_group_leaf_ids ( & e , leaf_ids , vm ) ;
2640- }
2643+ if let Ok ( excs_attr) = exc. get_attr ( "exceptions" , vm)
2644+ && let Ok ( tuple) = excs_attr. downcast :: < PyTuple > ( )
2645+ {
2646+ for e in tuple . iter ( ) {
2647+ collect_exception_group_leaf_ids ( e , leaf_ids , vm ) ;
26412648 }
26422649 }
26432650}
@@ -2689,7 +2696,7 @@ fn split_by_leaf_ids(
26892696
26902697 let mut matched = Vec :: new ( ) ;
26912698 for e in tuple. iter ( ) {
2692- let m = split_by_leaf_ids ( & e, leaf_ids, vm) ?;
2699+ let m = split_by_leaf_ids ( e, leaf_ids, vm) ?;
26932700 if !vm. is_none ( & m) {
26942701 matched. push ( m) ;
26952702 }
0 commit comments