Skip to content

Commit 93bb05f

Browse files
committed
Raises an exception if Downcast fails
1 parent d779bdf commit 93bb05f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/SWIG_files/common/OccHandle.i

+6-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,12 @@ WRAP_OCC_TRANSIENT(const, TYPE)
177177
}
178178
179179
opencascade::handle<TYPE> Handle_ ## TYPE ## _DownCast(const opencascade::handle<Standard_Transient>& t) {
180-
return opencascade::handle<TYPE>::DownCast(t);
180+
opencascade::handle<TYPE> downcasted_hanle = opencascade::handle<TYPE>::DownCast(t);
181+
if (downcasted_hanle.IsNull()) {
182+
PyErr_SetString(PyExc_RuntimeError, "Failed to downcast to TYPE.");
183+
return NULL;
184+
}
185+
return downcasted_hanle;
181186
}
182187
183188
bool Handle_ ## TYPE ## _IsNull(const opencascade::handle<TYPE> & t) {

test/core_wrapper_features_unittest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,8 @@ def test_downcast_curve(self) -> None:
606606
line = Geom_Line.DownCast(curve)
607607
self.assertTrue(isinstance(line, Geom_Curve))
608608
# Hence, it should not be possible to downcast it as a B-Spline curve
609-
bspline = Geom_BSplineCurve.DownCast(curve)
610-
self.assertTrue(bspline is None)
609+
with self.assertRaises(SystemError):
610+
Geom_BSplineCurve.DownCast(curve)
611611

612612
def test_return_enum(self) -> None:
613613
"""Check that returned enums are properly handled, whether they're returned

0 commit comments

Comments
 (0)