mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-11 08:03:55 +00:00
fix: type bug intruduced in #2492
This now tests the old form too, and fixes the bug introduced.
This commit is contained in:
parent
dec33c29f2
commit
11f756f5a9
@ -153,7 +153,7 @@ public:
|
|||||||
/// Return the object's current reference count
|
/// Return the object's current reference count
|
||||||
int ref_count() const { return static_cast<int>(Py_REFCNT(derived().ptr())); }
|
int ref_count() const { return static_cast<int>(Py_REFCNT(derived().ptr())); }
|
||||||
|
|
||||||
PYBIND11_DEPRECATED("Call py::type::handle_of(h) or py::type::of(h) instead of h.get_type()")
|
// TODO PYBIND11_DEPRECATED("Call py::type::handle_of(h) or py::type::of(h) instead of h.get_type()")
|
||||||
handle get_type() const;
|
handle get_type() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -1580,8 +1580,7 @@ template <typename D>
|
|||||||
str_attr_accessor object_api<D>::doc() const { return attr("__doc__"); }
|
str_attr_accessor object_api<D>::doc() const { return attr("__doc__"); }
|
||||||
|
|
||||||
template <typename D>
|
template <typename D>
|
||||||
PYBIND11_DEPRECATED("Use py::type::of(h) instead of h.get_type()")
|
handle object_api<D>::get_type() const { return type::handle_of(derived()); }
|
||||||
handle object_api<D>::get_type() const { return type::handle_of(*this); }
|
|
||||||
|
|
||||||
template <typename D>
|
template <typename D>
|
||||||
bool object_api<D>::rich_compare(object_api const &other, int value) const {
|
bool object_api<D>::rich_compare(object_api const &other, int value) const {
|
||||||
|
@ -152,6 +152,10 @@ TEST_SUBMODULE(class_, m) {
|
|||||||
return py::type::of(ob);
|
return py::type::of(ob);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
m.def("get_type_classic", [](py::handle h) {
|
||||||
|
return h.get_type();
|
||||||
|
});
|
||||||
|
|
||||||
m.def("as_type", [](py::object ob) {
|
m.def("as_type", [](py::object ob) {
|
||||||
auto tp = py::type(ob);
|
auto tp = py::type(ob);
|
||||||
if (py::isinstance<py::type>(ob))
|
if (py::isinstance<py::type>(ob))
|
||||||
|
@ -45,6 +45,12 @@ def test_type_of_py():
|
|||||||
assert m.get_type_of(int) == type
|
assert m.get_type_of(int) == type
|
||||||
|
|
||||||
|
|
||||||
|
def test_type_of_classic():
|
||||||
|
assert m.get_type_classic(1) == int
|
||||||
|
assert m.get_type_classic(m.DerivedClass1()) == m.DerivedClass1
|
||||||
|
assert m.get_type_classic(int) == type
|
||||||
|
|
||||||
|
|
||||||
def test_type_of_py_nodelete():
|
def test_type_of_py_nodelete():
|
||||||
# If the above test deleted the class, this will segfault
|
# If the above test deleted the class, this will segfault
|
||||||
assert m.get_type_of(m.DerivedClass1()) == m.DerivedClass1
|
assert m.get_type_of(m.DerivedClass1()) == m.DerivedClass1
|
||||||
|
Loading…
Reference in New Issue
Block a user