Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9cad0d5

Browse files
authored
Merge pull request #27868 from QuLogic/pybind11-str-format
Use pybind11 string formatter for exception messages
2 parents 2d5e293 + 9356137 commit 9cad0d5

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/_image_wrapper.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ _get_transform_mesh(const py::object& transform, const py::ssize_t *dims)
7878

7979
if (output_mesh_array.ndim() != 2) {
8080
throw std::runtime_error(
81-
"Inverse transformed mesh array should be 2D not " +
82-
std::to_string(output_mesh_array.ndim()) + "D");
81+
"Inverse transformed mesh array should be 2D not {}D"_s.format(
82+
output_mesh_array.ndim()));
8383
}
8484

8585
return output_mesh_array;
@@ -108,8 +108,8 @@ image_resample(py::array input_array,
108108

109109
if (ndim == 3 && input_array.shape(2) != 4) {
110110
throw std::invalid_argument(
111-
"3D input array must be RGBA with shape (M, N, 4), has trailing dimension of " +
112-
std::to_string(input_array.shape(2)));
111+
"3D input array must be RGBA with shape (M, N, 4), has trailing dimension of {}"_s.format(
112+
input_array.shape(2)));
113113
}
114114

115115
// Ensure input array is contiguous, regardless of dtype
@@ -120,14 +120,14 @@ image_resample(py::array input_array,
120120

121121
if (out_ndim != ndim) {
122122
throw std::invalid_argument(
123-
"Input (" + std::to_string(ndim) + "D) and output (" + std::to_string(out_ndim) +
124-
"D) arrays have different dimensionalities");
123+
"Input ({}D) and output ({}D) arrays have different dimensionalities"_s.format(
124+
ndim, out_ndim));
125125
}
126126

127127
if (out_ndim == 3 && output_array.shape(2) != 4) {
128128
throw std::invalid_argument(
129-
"3D output array must be RGBA with shape (M, N, 4), has trailing dimension of " +
130-
std::to_string(output_array.shape(2)));
129+
"3D output array must be RGBA with shape (M, N, 4), has trailing dimension of {}"_s.format(
130+
output_array.shape(2)));
131131
}
132132

133133
if (!output_array.dtype().is(dtype)) {

src/_tkagg.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,19 @@ mpl_tk_blit(py::object interp_obj, const char *photo_name,
9999

100100
auto data_ptr = data.mutable_unchecked<3>(); // Checks ndim and writeable flag.
101101
if (data.shape(2) != 4) {
102-
throw py::value_error("Data pointer must be RGBA; last dimension is " +
103-
std::to_string(data.shape(2)) + ", not 4");
102+
throw py::value_error(
103+
"Data pointer must be RGBA; last dimension is {}, not 4"_s.format(
104+
data.shape(2)));
104105
}
105106
if (data.shape(0) > INT_MAX) { // Limited by Tk_PhotoPutBlock argument type.
106107
throw std::range_error(
107-
"Height (" + std::to_string(data.shape(0)) +
108-
") exceeds maximum allowable size (" + std::to_string(INT_MAX) + ")");
108+
"Height ({}) exceeds maximum allowable size ({})"_s.format(
109+
data.shape(0), INT_MAX));
109110
}
110111
if (data.shape(1) > INT_MAX / 4) { // Limited by Tk_PhotoImageBlock.pitch field.
111112
throw std::range_error(
112-
"Width (" + std::to_string(data.shape(1)) +
113-
") exceeds maximum allowable size (" + std::to_string(INT_MAX / 4) + ")");
113+
"Width ({}) exceeds maximum allowable size ({})"_s.format(
114+
data.shape(1), INT_MAX / 4));
114115
}
115116
const auto height = static_cast<int>(data.shape(0));
116117
const auto width = static_cast<int>(data.shape(1));

0 commit comments

Comments
 (0)