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:
2026-06-13 21:19:03 +01:00
parent a7da4ea728
commit 7b6d43efeb
+6 -3
View File
@@ -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");