python: fix exception hierarchy — не вызывать .attr("__class__")
py::exception<T>(...) уже возвращает Python class object. Дополнительный
.attr("__class__") давал metaclass (type), из-за чего issubclass()
проверка для всех subexc возвращала False.
Verify: pytest tests/test_smoke.py — 5/5 passed.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -103,9 +103,12 @@ PYBIND11_MODULE(_native, m) {
|
||||
// Downstream code может ловить либо конкретный subtype, либо CuframesError
|
||||
// как catch-all.
|
||||
|
||||
g_exc.base = py::exception<std::runtime_error>(m, "CuframesError").attr("__class__");
|
||||
auto make_subexc = [&m](const char* name) {
|
||||
return py::exception<std::runtime_error>(m, name, g_exc.base.ptr()).attr("__class__");
|
||||
// py::exception<T>(...) уже возвращает py::object на сам Python class.
|
||||
// Не вызываем .attr("__class__") — иначе получим metaclass (type),
|
||||
// а не сам exception class.
|
||||
g_exc.base = py::exception<std::runtime_error>(m, "CuframesError");
|
||||
auto make_subexc = [&m](const char* name) -> py::object {
|
||||
return py::exception<std::runtime_error>(m, name, g_exc.base.ptr());
|
||||
};
|
||||
g_exc.publisher_gone = make_subexc("CuframesPublisherGone");
|
||||
g_exc.frame_timeout = make_subexc("CuframesFrameTimeout");
|
||||
|
||||
Reference in New Issue
Block a user