from typing import Optional, Union


def to_bytes(
    x: Union[str, bytes], encoding: Optional[str] = None, errors: Optional[str] = None
) -> bytes:
    if isinstance(x, bytes):
        return x
    elif not isinstance(x, str):
        raise TypeError(f"not expecting type {type(x).__name__}")
    elif encoding or errors:
        return x.encode(encoding or "utf-8", errors=errors or "strict")
    return x.encode()


def to_str(
    x: Union[str, bytes], encoding: Optional[str] = None, errors: Optional[str] = None
) -> str:
    if isinstance(x, str):
        return x
    elif not isinstance(x, bytes):
        raise TypeError(f"not expecting type {type(x).__name__}")
    elif encoding or errors:
        return x.decode(encoding or "utf-8", errors=errors or "strict")
    return x.decode()


def reraise(tp, value, tb=None):
    try:
        if value is None:
            value = tp()
        if value.__traceback__ is not tb:
            raise value.with_traceback(tb)
        raise value
    finally:
        value = None
        tb = None

@@ -1,8 +1,40 @@
+from types import TracebackType%0A
 from typ
@@ -43,16 +43,26 @@
 g import
+ NoReturn,
  Optiona
@@ -63,16 +63,22 @@
 ptional,
+ Type,
  Union%0A%0A
@@ -856,27 +856,137 @@
 ise(
-tp, value, tb=None)
+%0A    tp: Optional%5BType%5BBaseException%5D%5D,%0A    value: Optional%5BBaseException%5D,%0A    tb: Optional%5BTracebackType%5D = None,%0A) -%3E NoReturn
 :%0A  

Add types to util.reraise()