From c96c54d7d953616155a3424a08d2f5e3f1efabc1 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 1 Apr 2025 16:34:17 -0400 Subject: [PATCH] fix: fully deprecate get_type_of (deprecated in 2.6 but no warning Signed-off-by: Henry Schreiner --- include/pybind11/pybind11.h | 2 +- include/pybind11/pytypes.h | 3 +-- tests/test_class.cpp | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 75a0b49695..e3c29e25f8 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -2520,7 +2520,7 @@ detail::initimpl::pickle_factory pickle(GetState &&g, SetSta PYBIND11_NAMESPACE_BEGIN(detail) inline str enum_name(handle arg) { - dict entries = arg.get_type().attr("__entries"); + dict entries = type::handle_of(arg).attr("__entries"); for (auto kv : entries) { if (handle(kv.second[int_(0)]).equal(arg)) { return pybind11::str(kv.first); diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index e01c7b0b96..db07a03139 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -210,8 +210,7 @@ class object_api : public pyobject_tag { #endif } - // TODO PYBIND11_DEPRECATED( - // "Call py::type::handle_of(h) or py::type::of(h) instead of h.get_type()") + PYBIND11_DEPRECATED("Call py::type::handle_of(h) or py::type::of(h) instead of h.get_type()") handle get_type() const; private: diff --git a/tests/test_class.cpp b/tests/test_class.cpp index 28dc313334..3d567fc1f5 100644 --- a/tests/test_class.cpp +++ b/tests/test_class.cpp @@ -219,7 +219,7 @@ TEST_SUBMODULE(class_, m) { m.def("get_type_of", [](py::object ob) { return py::type::of(std::move(ob)); }); - m.def("get_type_classic", [](py::handle h) { return h.get_type(); }); + m.def("get_type_classic", [](py::handle h) { return py::type::handle_of(h); }); m.def("as_type", [](const py::object &ob) { return py::type(ob); });