fn err_if_invalid_value<T: PartialEq>( py: Python<'_>, invalid_value: T, actual_value: T, ) -> PyResult<T>