Skip to content

fix/typebug #2497

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 2 commits into from
Sep 17, 2020
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
5 changes: 2 additions & 3 deletions include/pybind11/pytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class object_api : public pyobject_tag {
/// Return the object's current reference count
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;

private:
Expand Down Expand Up @@ -1580,8 +1580,7 @@ template <typename D>
str_attr_accessor object_api<D>::doc() const { return attr("__doc__"); }

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(*this); }
handle object_api<D>::get_type() const { return type::handle_of(derived()); }

template <typename D>
bool object_api<D>::rich_compare(object_api const &other, int value) const {
Expand Down
4 changes: 4 additions & 0 deletions tests/test_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ TEST_SUBMODULE(class_, m) {
return py::type::of(ob);
});

m.def("get_type_classic", [](py::handle h) {
return h.get_type();
});

m.def("as_type", [](py::object ob) {
auto tp = py::type(ob);
if (py::isinstance<py::type>(ob))
Expand Down
6 changes: 6 additions & 0 deletions tests/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def test_type_of_py():
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():
# If the above test deleted the class, this will segfault
assert m.get_type_of(m.DerivedClass1()) == m.DerivedClass1
Expand Down
8 changes: 4 additions & 4 deletions tests/test_gil_scoped.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _python_to_cpp_to_python_from_threads(num_threads, parallel=False):


# TODO: FIXME, sometimes returns -11 instead of 0
@pytest.mark.xfail("env.PY > (3,8) and env.MACOS", strict=False)
@pytest.mark.xfail("env.PY >= (3,9) and env.MACOS", strict=False)
def test_python_to_cpp_to_python_from_thread():
"""Makes sure there is no GIL deadlock when running in a thread.

Expand All @@ -65,7 +65,7 @@ def test_python_to_cpp_to_python_from_thread():


# TODO: FIXME
@pytest.mark.xfail("env.PY > (3,8) and env.MACOS", strict=False)
@pytest.mark.xfail("env.PY >= (3,9) and env.MACOS", strict=False)
def test_python_to_cpp_to_python_from_thread_multiple_parallel():
"""Makes sure there is no GIL deadlock when running in a thread multiple times in parallel.

Expand All @@ -75,7 +75,7 @@ def test_python_to_cpp_to_python_from_thread_multiple_parallel():


# TODO: FIXME
@pytest.mark.xfail("env.PY > (3,8) and env.MACOS", strict=False)
@pytest.mark.xfail("env.PY >= (3,9) and env.MACOS", strict=False)
def test_python_to_cpp_to_python_from_thread_multiple_sequential():
"""Makes sure there is no GIL deadlock when running in a thread multiple times sequentially.

Expand All @@ -85,7 +85,7 @@ def test_python_to_cpp_to_python_from_thread_multiple_sequential():


# TODO: FIXME
@pytest.mark.xfail("env.PY > (3,8) and env.MACOS", strict=False)
@pytest.mark.xfail("env.PY >= (3,9) and env.MACOS", strict=False)
def test_python_to_cpp_to_python_from_process():
"""Makes sure there is no GIL deadlock when using processes.

Expand Down