From 8d14e666e3aab5c958169e23b619ae8b17b09ea6 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 26 May 2022 08:07:40 -0700 Subject: [PATCH] fix: avoid `catch (...)` for expected `import numpy` failures (#3974) * Replace import numpy catch (...) with catch (error_already_set) * Add missing const (not sure how those got lost). --- tests/test_numpy_array.cpp | 2 +- tests/test_numpy_dtypes.cpp | 2 +- tests/test_numpy_vectorize.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_numpy_array.cpp b/tests/test_numpy_array.cpp index 8bc77a33f..69ddbe1ef 100644 --- a/tests/test_numpy_array.cpp +++ b/tests/test_numpy_array.cpp @@ -162,7 +162,7 @@ static int data_i = 42; TEST_SUBMODULE(numpy_array, sm) { try { py::module_::import("numpy"); - } catch (...) { + } catch (const py::error_already_set &) { return; } diff --git a/tests/test_numpy_dtypes.cpp b/tests/test_numpy_dtypes.cpp index c25bc042b..6654f9ed8 100644 --- a/tests/test_numpy_dtypes.cpp +++ b/tests/test_numpy_dtypes.cpp @@ -301,7 +301,7 @@ struct B {}; TEST_SUBMODULE(numpy_dtypes, m) { try { py::module_::import("numpy"); - } catch (...) { + } catch (const py::error_already_set &) { return; } diff --git a/tests/test_numpy_vectorize.cpp b/tests/test_numpy_vectorize.cpp index eab08ec0a..dcc4c6ac2 100644 --- a/tests/test_numpy_vectorize.cpp +++ b/tests/test_numpy_vectorize.cpp @@ -22,7 +22,7 @@ double my_func(int x, float y, double z) { TEST_SUBMODULE(numpy_vectorize, m) { try { py::module_::import("numpy"); - } catch (...) { + } catch (const py::error_already_set &) { return; }