diff --git a/src/typeguard/_checkers.py b/src/typeguard/_checkers.py index 34bff23..145312f 100644 --- a/src/typeguard/_checkers.py +++ b/src/typeguard/_checkers.py @@ -405,7 +405,10 @@ def check_union( formatted_errors = indent( "\n".join(f"{key}: {error}" for key, error in errors.items()), " " ) - raise TypeCheckError(f"did not match any element in the union:\n{formatted_errors}") + try: + raise TypeCheckError(f"did not match any element in the union:\n{formatted_errors}") + finally: + del errors def check_uniontype(