def METHOD_NAME(data: bytes, **kwargs) -> mock._patch:
    """Patches `open` to return return a `BytesIO` object.
    This is similar to calling `patch("builtins.open, new_callable=mock_open, ...)`,
    but returns a real IO-type object that supports everything that the usual
    file object returned by open supports, ensuring greater compatibility with
    arbitrary libraries at the cost of not resetting itself each time its called."""
    def _new_mock():
        omock = mock.MagicMock(name="open", spec="open")
        omock.side_effect = lambda *args, **kwargs: BytesIO(data)
        return omock
    return patch("builtins.open", new_callable=_new_mock, **kwargs)