Facepalm, fix `raise from` in `collapse_eg()`
I dunno what exactly I was thinking but we definitely don't want to **ever** raise from the original exc-group, instead always raise from any original `.__cause__` to be consistent with the embedded src-error's context. Also, adjust `maybe_collapse_eg()` to return `False` in the non-single `.exceptions` case, again don't know what I was trying to do but this simplifies caller logic and the prior return-semantic had no real value.. This fixes some final usage in the runtime (namely top level nursery usage in `._root`/`._runtime`) which was previously causing test suite failures prior to this fix.cluster_api_egs_conflict
							parent
							
								
									b244cf844d
								
							
						
					
					
						commit
						f86f4ae48d
					
				| 
						 | 
				
			
			@ -31,7 +31,7 @@ import trio
 | 
			
		|||
 | 
			
		||||
def maybe_collapse_eg(
 | 
			
		||||
    beg: BaseExceptionGroup,
 | 
			
		||||
) -> BaseException:
 | 
			
		||||
) -> BaseException|bool:
 | 
			
		||||
    '''
 | 
			
		||||
    If the input beg can collapse to a single non-eg sub-exception,
 | 
			
		||||
    return it instead.
 | 
			
		||||
| 
						 | 
				
			
			@ -40,13 +40,12 @@ def maybe_collapse_eg(
 | 
			
		|||
    if len(excs := beg.exceptions) == 1:
 | 
			
		||||
        return excs[0]
 | 
			
		||||
 | 
			
		||||
    return beg
 | 
			
		||||
    return False
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@acm
 | 
			
		||||
async def collapse_eg(
 | 
			
		||||
    hide_tb: bool = True,
 | 
			
		||||
    raise_from_src: bool = False,
 | 
			
		||||
):
 | 
			
		||||
    '''
 | 
			
		||||
    If `BaseExceptionGroup` raised in the body scope is
 | 
			
		||||
| 
						 | 
				
			
			@ -61,9 +60,11 @@ async def collapse_eg(
 | 
			
		|||
    except* BaseException as beg:
 | 
			
		||||
        if (
 | 
			
		||||
            exc := maybe_collapse_eg(beg)
 | 
			
		||||
        ) is not beg:
 | 
			
		||||
            from_exc = beg if raise_from_src else None
 | 
			
		||||
            raise exc from from_exc
 | 
			
		||||
        ):
 | 
			
		||||
            if cause := exc.__cause__:
 | 
			
		||||
                raise exc from cause
 | 
			
		||||
 | 
			
		||||
            raise exc
 | 
			
		||||
 | 
			
		||||
        raise beg
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue