Skip to content

Commit b457367

Browse files
sizmailovpre-commit-ci[bot]rwgk
authored
Update render for buffer sequence and handle (#4831)
* fix: Add capitalize render name of `py::buffer` and `py::sequence` * fix: Render `py::handle` same way as `py::object` * tests: Fix tests `handle` -> `object` * tests: Test capitaliation of `py::sequence` and `py::buffer` * style: pre-commit fixes * fix: Render `py::object` as `Any` * Revert "fix: Render `py::object` as `Any`" This reverts commit 7861dcf. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ralf W. Grosse-Kunstleve <[email protected]>
1 parent c9149d9 commit b457367

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

include/pybind11/cast.h

+12
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,10 @@ struct handle_type_name<bytes> {
882882
static constexpr auto name = const_name(PYBIND11_BYTES_NAME);
883883
};
884884
template <>
885+
struct handle_type_name<buffer> {
886+
static constexpr auto name = const_name("Buffer");
887+
};
888+
template <>
885889
struct handle_type_name<int_> {
886890
static constexpr auto name = const_name("int");
887891
};
@@ -902,10 +906,18 @@ struct handle_type_name<function> {
902906
static constexpr auto name = const_name("Callable");
903907
};
904908
template <>
909+
struct handle_type_name<handle> {
910+
static constexpr auto name = handle_type_name<object>::name;
911+
};
912+
template <>
905913
struct handle_type_name<none> {
906914
static constexpr auto name = const_name("None");
907915
};
908916
template <>
917+
struct handle_type_name<sequence> {
918+
static constexpr auto name = const_name("Sequence");
919+
};
920+
template <>
909921
struct handle_type_name<args> {
910922
static constexpr auto name = const_name("*args");
911923
};

tests/test_buffers.py

+7
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,10 @@ def test_ctypes_from_buffer():
219219
assert cinfo.shape == pyinfo.shape
220220
assert cinfo.strides == pyinfo.strides
221221
assert not cinfo.readonly
222+
223+
224+
def test_buffer_docstring():
225+
assert (
226+
m.get_buffer_info.__doc__.strip()
227+
== "get_buffer_info(arg0: Buffer) -> pybind11_tests.buffers.buffer_info"
228+
)

tests/test_factory_constructors.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_init_factory_signature(msg):
7777
1. m.factory_constructors.TestFactory1(arg0: m.factory_constructors.tag.unique_ptr_tag, arg1: int)
7878
2. m.factory_constructors.TestFactory1(arg0: str)
7979
3. m.factory_constructors.TestFactory1(arg0: m.factory_constructors.tag.pointer_tag)
80-
4. m.factory_constructors.TestFactory1(arg0: handle, arg1: int, arg2: handle)
80+
4. m.factory_constructors.TestFactory1(arg0: object, arg1: int, arg2: object)
8181
8282
Invoked with: 'invalid', 'constructor', 'arguments'
8383
"""
@@ -95,7 +95,7 @@ def test_init_factory_signature(msg):
9595
9696
3. __init__(self: m.factory_constructors.TestFactory1, arg0: m.factory_constructors.tag.pointer_tag) -> None
9797
98-
4. __init__(self: m.factory_constructors.TestFactory1, arg0: handle, arg1: int, arg2: handle) -> None
98+
4. __init__(self: m.factory_constructors.TestFactory1, arg0: object, arg1: int, arg2: object) -> None
9999
"""
100100
)
101101

tests/test_sequences_and_iterators.py

+4
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ def __len__(self):
171171
assert m.sequence_length("hello") == 5
172172

173173

174+
def test_sequence_doc():
175+
assert m.sequence_length.__doc__.strip() == "sequence_length(arg0: Sequence) -> int"
176+
177+
174178
def test_map_iterator():
175179
sm = m.StringMap({"hi": "bye", "black": "white"})
176180
assert sm["hi"] == "bye"

0 commit comments

Comments
 (0)