File tree 3 files changed +12
-3
lines changed 3 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -153,7 +153,7 @@ class object_api : public pyobject_tag {
153
153
// / Return the object's current reference count
154
154
int ref_count () const { return static_cast <int >(Py_REFCNT (derived ().ptr ())); }
155
155
156
- PYBIND11_DEPRECATED (" Call py::type::handle_of(h) or py::type::of(h) instead of h.get_type()" )
156
+ // TODO PYBIND11_DEPRECATED("Call py::type::handle_of(h) or py::type::of(h) instead of h.get_type()")
157
157
handle get_type () const ;
158
158
159
159
private:
@@ -1580,8 +1580,7 @@ template <typename D>
1580
1580
str_attr_accessor object_api<D>::doc() const { return attr (" __doc__" ); }
1581
1581
1582
1582
template <typename D>
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 ); }
1583
+ handle object_api<D>::get_type() const { return type::handle_of (derived ()); }
1585
1584
1586
1585
template <typename D>
1587
1586
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