(content: types.AnyStr, file_mode: str)
return content
If the `content` to be written to file and the `file_mode` used to open it
    are incompatible (either bytes with text mode or unicode with bytes mode),
    try to coerce the content type so it can be written.
If the `content` to be written to file and the `file_mode` used to open it
    are incompatible (either bytes with text mode or unicode with bytes mode),
    try to coerce the content type so it can be written.
If the content to be written to file and the file_mode used to open it are incompatible ( either bytes with text mode or unicode with bytes mode ) try to coerce the content type so it can be written .
def coerce_content_type(content: types.AnyStr, file_mode: str) -> str | bytes:
    """
    If the `content` to be written to file and the `file_mode` used to open it
    are incompatible (either bytes with text mode or unicode with bytes mode),
    try to coerce the content type so it can be written.
    """
    if "t" in file_mode:
        return utils.to_unicode(content)
    elif "b" in file_mode:
        return utils.to_bytes(content)
    return content
def coerce_content_type ( content : types . AnyStr , file_mode : str ) -> str | bytes : if "t" in file_mode : return utils . to_unicode ( content ) elif "b" in file_mode : return utils . to_bytes ( content ) return content