Skip to content

Commit 5ccb893

Browse files
committed
Change type_caster<PyObject>::name to object, as suggested by @Skylion007
1 parent 9907943 commit 5ccb893

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

include/pybind11/type_caster_pyobject_ptr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ PYBIND11_NAMESPACE_BEGIN(detail)
1313
template <>
1414
class type_caster<PyObject> {
1515
public:
16-
static constexpr auto name = const_name("PyObject *");
16+
static constexpr auto name = const_name("object"); // See discussion under PR #4601.
1717

1818
// This overload is purely to guard against accidents.
1919
template <typename T,

tests/test_type_caster_pyobject_ptr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ TEST_SUBMODULE(type_caster_pyobject_ptr, m) {
9898
return i;
9999
});
100100

101+
m.def("pass_pyobject_ptr_and_int", [](PyObject *, int) {});
102+
101103
#ifdef PYBIND11_NO_COMPILE_SECTION // Change to ifndef for manual testing.
102104
{
103105
PyObject *ptr = nullptr;

tests/test_type_caster_pyobject_ptr.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,8 @@ def test_return_list_pyobject_ptr_reference():
8989
# Insert `while True:` as the first line of this function and monitor the
9090
# process RES (Resident Memory Size) with the Unix top command.
9191
assert m.dec_ref_each_pyobject_ptr(vec_obj) == 2
92+
93+
94+
def test_type_caster_name_via_incompatible_function_arguments_type_error():
95+
with pytest.raises(TypeError, match=r"1\. \(arg0: object, arg1: int\) -> None"):
96+
m.pass_pyobject_ptr_and_int(ValueHolder(101), ValueHolder(202))

0 commit comments

Comments
 (0)