Download Python/train/3.13/exception-groups/modern_06.py from SwashBuckler001/idiombench: direct link, hf CLI and curl.
- Browser
- Download file 615 Bytes
-
https://huggingface.co/datasets/SwashBuckler001/idiombench/resolve/main/Python/train/3.13/exception-groups/modern_06.py
- Command line
-
hf download hf://datasets/SwashBuckler001/idiombench/Python/train/3.13/exception-groups/modern_06.py
-
curl -L -o modern_06.py https://huggingface.co/datasets/SwashBuckler001/idiombench/resolve/main/Python/train/3.13/exception-groups/modern_06.py
615 Bytes
| def leaf_generator(exc, tbs=None): | |
| if tbs is None: | |
| tbs = [] | |
| tbs.append(exc.__traceback__) | |
| if isinstance(exc, BaseExceptionGroup): | |
| for e in exc.exceptions: | |
| yield from leaf_generator(e, tbs) | |
| else: | |
| # exc is a leaf exception and its traceback | |
| # is the concatenation of the traceback | |
| # segments in tbs. | |
| # Note: the list returned (tbs) is reused in each iteration | |
| # through the generator. Make a copy if your use case holds | |
| # on to it beyond the current iteration or mutates its contents. | |
| yield exc, tbs | |
| tbs.pop() | |