def replace_exceptions(<EOL>old_to_new_exceptions: Dict[Type[BaseException], Type[BaseException]]<EOL>) -> Callable[..., Any]:
old_exceptions = tuple(old_to_new_exceptions.keys())<EOL>def decorator(to_wrap: Callable[..., Any]) -> Callable[..., Any]:<EOL><INDENT>@functools.wraps(to_wrap)<EOL>def wrapper(<EOL>*args: Iterable[Any], **kwargs: Dict[str, Any]<EOL>) -> Callable[..., Any]:<EOL><INDENT>try:<EOL><INDENT>return to_wrap(*args, **kwargs)<EOL><DEDENT>except old_exceptions as err:<EOL><INDENT>try:<EOL><INDENT>raise old_to_new_exceptions[type(err)] from err<EOL><DEDENT>except KeyError:<EOL><INDENT>raise TypeError(<EOL>"<STR_LIT>" % err<EOL>) from err<EOL><DEDENT><DEDENT><DEDENT>return wrapper<EOL><DEDENT>return decorator<EOL>
Replaces old exceptions with new exceptions to be raised in their place.