| 16 | template<typename F> |
| 17 | requires std::convertible_to<std::invoke_result_t<F>, PyObject*> |
| 18 | PyObject* CallWithErrorTranslation(F&& f) noexcept { |
| 19 | try { |
| 20 | return std::forward<F>(f)(); |
| 21 | } catch (const std::bad_alloc& err) { |
| 22 | PyErr_SetString(PyExc_MemoryError, err.what()); |
| 23 | } catch(const std::out_of_range& err) { |
| 24 | PyErr_SetString(PyExc_IndexError, err.what()); |
| 25 | } catch (const std::exception& err) { |
| 26 | PyErr_SetString(PyExc_RuntimeError, err.what()); |
| 27 | } catch(...) { |
| 28 | PyErr_SetString(PyExc_RuntimeError, "Unhandled C++ exception of unknown type"); |
| 29 | } |
| 30 | return nullptr; |
| 31 | } |
| 32 | |
| 33 | PyObject* Count(PyObject* self[[maybe_unused]], PyObject *args[[maybe_unused]]) noexcept { |
| 34 | static_assert( |
no test coverage detected