(
    s: types.AnyStr, *, encoding: str = "utf-8", errors: str = "strict"
)
Coerce string ``s`` to bytes.
Coerce string ``s`` to bytes.
Coerce string s to bytes .
def to_bytes(
    s: types.AnyStr, *, encoding: str = "utf-8", errors: str = "strict"
) -> bytes:
    """Coerce string ``s`` to bytes."""
    if isinstance(s, str):
        return s.encode(encoding, errors)
    elif isinstance(s, bytes):
        return s
    else:
        raise TypeError(errors_.type_invalid_msg("s", type(s), Union[str, bytes]))
def to_bytes ( s : types . AnyStr , * , encoding : str = "utf-8" , errors : str = "strict" ) -> bytes : if isinstance ( s , str ) : return s . encode ( encoding , errors ) elif isinstance ( s , bytes ) : return s else : raise TypeError ( errors_ . type_invalid_msg ( "s" , type ( s ) , Union [ str , bytes ] ) )