Skip to content

fix: fully deprecate get_type_of (deprecated in 2.6 but no warning) #5596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -2520,7 +2520,7 @@ detail::initimpl::pickle_factory<GetState, SetState> 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);
Expand Down
3 changes: 1 addition & 2 deletions include/pybind11/pytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); });

Expand Down
Loading