def parse_metadata(fp: IO[bytes]) -> email.message.Message:
    """
    Note that this function will close fp. See https://github.com/python/cpython/issues/65562.
    """
    with io.TextIOWrapper(fp, encoding="utf-8", errors="surrogateescape") as file:
        return email.message_from_file(file, policy=UTF8_POLICY)  # type: ignore[arg-type]

    Note that this function will close fp. See https://github.com/python/cpython/issues/65562.
    
src/pdm/cli/commands/publish/package.py