From 3b5df0d8aedfa6a7fae344bd35c89216a620f73b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 1 Jan 2026 16:40:39 +0100 Subject: [PATCH] python: fix deprecation warnings with pybing11 3.0. --- src/python/magnum/gl.cpp | 63 ++++++++++++++++++++++++++++++---- src/python/magnum/scenegraph.h | 9 ++++- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/src/python/magnum/gl.cpp b/src/python/magnum/gl.cpp index 07e712b..ae868e4 100644 --- a/src/python/magnum/gl.cpp +++ b/src/python/magnum/gl.cpp @@ -151,7 +151,14 @@ template void texture(py::class_ else if(py::isinstance(tuple[0])) filter = py::cast(tuple[0]); else { - PyErr_Format(PyExc_TypeError, "expected a tuple with SamplerFilter or gl.SamplerFilter as the first element, got %A", value.get_type().ptr()); + PyErr_Format(PyExc_TypeError, "expected a tuple with SamplerFilter or gl.SamplerFilter as the first element, got %A", + /* get_type() deprecated in 2.6, warning in 3.0+ */ + #if PYBIND11_VERSION_MAJOR*100 + PYBIND11_VERSION_MINOR >= 206 + py::type::handle_of(value).ptr() + #else + value.get_type().ptr() + #endif + ); throw py::error_already_set{}; } @@ -161,13 +168,27 @@ template void texture(py::class_ else if(py::isinstance(tuple[1])) mipmap = py::cast(tuple[1]); else { - PyErr_Format(PyExc_TypeError, "expected a tuple with SamplerMipmap or gl.SamplerMipmap as the second element, got %A", value.get_type().ptr()); + PyErr_Format(PyExc_TypeError, "expected a tuple with SamplerMipmap or gl.SamplerMipmap as the second element, got %A", + /* get_type() deprecated in 2.6, warning in 3.0+ */ + #if PYBIND11_VERSION_MAJOR*100 + PYBIND11_VERSION_MINOR >= 206 + py::type::handle_of(value).ptr() + #else + value.get_type().ptr() + #endif + ); throw py::error_already_set{}; } self.setMinificationFilter(filter, mipmap); } else { - PyErr_Format(PyExc_TypeError, "expected SamplerFilter, gl.SamplerFilter or a two-element tuple, got %A", value.get_type().ptr()); + PyErr_Format(PyExc_TypeError, "expected SamplerFilter, gl.SamplerFilter or a two-element tuple, got %A", + /* get_type() deprecated since 2.6, warning in 3.0+ */ + #if PYBIND11_VERSION_MAJOR*100 + PYBIND11_VERSION_MINOR >= 206 + py::type::handle_of(value).ptr() + #else + value.get_type().ptr() + #endif + ); throw py::error_already_set{}; } }, "Minification filter") @@ -178,7 +199,14 @@ template void texture(py::class_ else if(py::isinstance(filter)) self.setMagnificationFilter(py::cast(filter)); else { - PyErr_Format(PyExc_TypeError, "expected SamplerFilter or gl.SamplerFilter, got %A", filter.get_type().ptr()); + PyErr_Format(PyExc_TypeError, "expected SamplerFilter or gl.SamplerFilter, got %A", + /* get_type() deprecated since 2.6, warning in 3.0+ */ + #if PYBIND11_VERSION_MAJOR*100 + PYBIND11_VERSION_MINOR >= 206 + py::type::handle_of(filter).ptr() + #else + filter.get_type().ptr() + #endif + ); throw py::error_already_set{}; } }, "Magnification filter") @@ -197,7 +225,14 @@ template void texture(py::class_ else if(py::isinstance(wrapping)) self.setWrapping(py::cast(wrapping)); else { - PyErr_Format(PyExc_TypeError, "expected SamplerWrapping or gl.SamplerWrapping, got %A", wrapping.get_type().ptr()); + PyErr_Format(PyExc_TypeError, "expected SamplerWrapping or gl.SamplerWrapping, got %A", + /* get_type() deprecated since 2.6, warning in 3.0+ */ + #if PYBIND11_VERSION_MAJOR*100 + PYBIND11_VERSION_MINOR >= 206 + py::type::handle_of(wrapping).ptr() + #else + wrapping.get_type().ptr() + #endif + ); throw py::error_already_set{}; } }, "Wrapping") @@ -216,7 +251,14 @@ template void texture(py::class_ else if(py::isinstance(color)) self.setBorderColor(py::cast(color)); else { - PyErr_Format(PyExc_TypeError, "expected Color3, Color4, Vector4ui or Vector4i, got %A", color.get_type().ptr()); + PyErr_Format(PyExc_TypeError, "expected Color3, Color4, Vector4ui or Vector4i, got %A", + /* get_type() deprecated since 2.6, warning in 3.0+ */ + #if PYBIND11_VERSION_MAJOR*100 + PYBIND11_VERSION_MINOR >= 206 + py::type::handle_of(color).ptr() + #else + color.get_type().ptr() + #endif + ); throw py::error_already_set{}; } }, @@ -936,7 +978,14 @@ void gl(py::module_& m) { else if(py::isinstance(primitive)) self.setPrimitive(py::cast(primitive)); else { - PyErr_Format(PyExc_TypeError, "expected MeshPrimitive or gl.MeshPrimitive, got %A", primitive.get_type().ptr()); + PyErr_Format(PyExc_TypeError, "expected MeshPrimitive or gl.MeshPrimitive, got %A", + /* get_type() deprecated since 2.6, warning in 3.0+ */ + #if PYBIND11_VERSION_MAJOR*100 + PYBIND11_VERSION_MINOR >= 206 + py::type::handle_of(primitive).ptr() + #else + primitive.get_type().ptr() + #endif + ); throw py::error_already_set{}; } }, "Primitive type") diff --git a/src/python/magnum/scenegraph.h b/src/python/magnum/scenegraph.h index aa851fa..2500dfd 100644 --- a/src/python/magnum/scenegraph.h +++ b/src/python/magnum/scenegraph.h @@ -62,7 +62,14 @@ template void object(py:: else if(py::isinstance(parentobj)) parent = nullptr; else { - PyErr_Format(PyExc_TypeError, "expected Scene, Object or None, got %A", parentobj.get_type().ptr()); + PyErr_Format(PyExc_TypeError, "expected Scene, Object or None, got %A", + /* get_type() deprecated since 2.6, is a warning in 3.0+ */ + #if PYBIND11_VERSION_MAJOR*100 + PYBIND11_VERSION_MINOR >= 206 + py::type::handle_of(parentobj).ptr() + #else + parentobj.get_type().ptr() + #endif + ); throw py::error_already_set{}; }