File tree Expand file tree Collapse file tree 3 files changed +11
-1
lines changed
Expand file tree Collapse file tree 3 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -1581,7 +1581,7 @@ str_attr_accessor object_api<D>::doc() const { return attr("__doc__"); }
15811581
15821582template <typename D>
15831583PYBIND11_DEPRECATED (" Use py::type::of(h) instead of h.get_type()" )
1584- handle object_api<D>::get_type() const { return type::handle_of (* this ); }
1584+ handle object_api<D>::get_type() const { return type::handle_of (derived () ); }
15851585
15861586template <typename D>
15871587bool object_api<D>::rich_compare(object_api const &other, int value) const {
Original file line number Diff line number Diff line change @@ -152,6 +152,10 @@ TEST_SUBMODULE(class_, m) {
152152 return py::type::of (ob);
153153 });
154154
155+ m.def (" get_type_classic" , [](py::handle h) {
156+ return h.get_type ();
157+ });
158+
155159 m.def (" as_type" , [](py::object ob) {
156160 auto tp = py::type (ob);
157161 if (py::isinstance<py::type>(ob))
Original file line number Diff line number Diff line change @@ -45,6 +45,12 @@ def test_type_of_py():
4545 assert m .get_type_of (int ) == type
4646
4747
48+ def test_type_of_classic ():
49+ assert m .get_type_classic (1 ) == int
50+ assert m .get_type_classic (m .DerivedClass1 ()) == m .DerivedClass1
51+ assert m .get_type_classic (int ) == type
52+
53+
4854def test_type_of_py_nodelete ():
4955 # If the above test deleted the class, this will segfault
5056 assert m .get_type_of (m .DerivedClass1 ()) == m .DerivedClass1
You can’t perform that action at this time.
0 commit comments