File tree 3 files changed +11
-1
lines changed
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__"); }
1581
1581
1582
1582
template <typename D>
1583
1583
PYBIND11_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 () ); }
1585
1585
1586
1586
template <typename D>
1587
1587
bool 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) {
152
152
return py::type::of (ob);
153
153
});
154
154
155
+ m.def (" get_type_classic" , [](py::handle h) {
156
+ return h.get_type ();
157
+ });
158
+
155
159
m.def (" as_type" , [](py::object ob) {
156
160
auto tp = py::type (ob);
157
161
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():
45
45
assert m .get_type_of (int ) == type
46
46
47
47
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
+
48
54
def test_type_of_py_nodelete ():
49
55
# If the above test deleted the class, this will segfault
50
56
assert m .get_type_of (m .DerivedClass1 ()) == m .DerivedClass1
You can’t perform that action at this time.
0 commit comments