Skip to content

Commit a2b0b88

Browse files
pybind11 type_caster for queue/device convert Py_None to default constructed instances (#773)
1 parent ae7a445 commit a2b0b88

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

dpctl/apis/include/dpctl4pybind11.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ template <> struct type_caster<sycl::queue>
5555
value = *q;
5656
return true;
5757
}
58+
else if (source == Py_None) {
59+
value = sycl::queue{};
60+
return true;
61+
}
5862
else {
59-
throw std::runtime_error(
63+
throw py::type_error(
6064
"Input is of unexpected type, expected dpctl.SyclQueue");
6165
}
6266
}
@@ -87,8 +91,12 @@ template <> struct type_caster<sycl::device>
8791
value = *d;
8892
return true;
8993
}
94+
else if (source == Py_None) {
95+
value = sycl::device{};
96+
return true;
97+
}
9098
else {
91-
throw std::runtime_error(
99+
throw py::type_error(
92100
"Input is of unexpected type, expected dpctl.SyclDevice");
93101
}
94102
}
@@ -120,7 +128,7 @@ template <> struct type_caster<sycl::context>
120128
return true;
121129
}
122130
else {
123-
throw std::runtime_error(
131+
throw py::type_error(
124132
"Input is of unexpected type, expected dpctl.SyclContext");
125133
}
126134
}
@@ -153,7 +161,7 @@ template <> struct type_caster<sycl::event>
153161
return true;
154162
}
155163
else {
156-
throw std::runtime_error(
164+
throw py::type_error(
157165
"Input is of unexpected type, expected dpctl.SyclEvent");
158166
}
159167
}

0 commit comments

Comments
 (0)