Skip to content
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

fix(types): update render for buffer sequence and handle #4831

Merged
16 changes: 16 additions & 0 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,10 @@ struct handle_type_name<bytes> {
static constexpr auto name = const_name(PYBIND11_BYTES_NAME);
};
template <>
struct handle_type_name<buffer> {
static constexpr auto name = const_name("Buffer");
};
template <>
struct handle_type_name<int_> {
static constexpr auto name = const_name("int");
};
Expand All @@ -902,10 +906,22 @@ struct handle_type_name<function> {
static constexpr auto name = const_name("Callable");
};
template <>
struct handle_type_name<object> {
static constexpr auto name = const_name("Any");
};
template <>
struct handle_type_name<handle> {
static constexpr auto name = handle_type_name<object>::name;
};
template <>
struct handle_type_name<none> {
static constexpr auto name = const_name("None");
};
template <>
struct handle_type_name<sequence> {
static constexpr auto name = const_name("Sequence");
};
template <>
struct handle_type_name<args> {
static constexpr auto name = const_name("*args");
};
Expand Down
7 changes: 7 additions & 0 deletions tests/test_buffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,10 @@ def test_ctypes_from_buffer():
assert cinfo.shape == pyinfo.shape
assert cinfo.strides == pyinfo.strides
assert not cinfo.readonly


def test_buffer_docstring():
assert (
m.get_buffer_info.__doc__.strip()
== "get_buffer_info(arg0: Buffer) -> pybind11_tests.buffers.buffer_info"
)
2 changes: 1 addition & 1 deletion tests/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,5 @@ def test_custom_func2():
def test_callback_docstring():
assert (
m.test_tuple_unpacking.__doc__.strip()
== "test_tuple_unpacking(arg0: Callable) -> object"
== "test_tuple_unpacking(arg0: Callable) -> Any"
)
4 changes: 2 additions & 2 deletions tests/test_factory_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_init_factory_signature(msg):
1. m.factory_constructors.TestFactory1(arg0: m.factory_constructors.tag.unique_ptr_tag, arg1: int)
2. m.factory_constructors.TestFactory1(arg0: str)
3. m.factory_constructors.TestFactory1(arg0: m.factory_constructors.tag.pointer_tag)
4. m.factory_constructors.TestFactory1(arg0: handle, arg1: int, arg2: handle)
4. m.factory_constructors.TestFactory1(arg0: Any, arg1: int, arg2: Any)

Invoked with: 'invalid', 'constructor', 'arguments'
"""
Expand All @@ -95,7 +95,7 @@ def test_init_factory_signature(msg):

3. __init__(self: m.factory_constructors.TestFactory1, arg0: m.factory_constructors.tag.pointer_tag) -> None

4. __init__(self: m.factory_constructors.TestFactory1, arg0: handle, arg1: int, arg2: handle) -> None
4. __init__(self: m.factory_constructors.TestFactory1, arg0: Any, arg1: int, arg2: Any) -> None
"""
)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_numpy_vectorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_docs(doc):
assert (
doc(m.vectorized_func)
== """
vectorized_func(arg0: numpy.ndarray[numpy.int32], arg1: numpy.ndarray[numpy.float32], arg2: numpy.ndarray[numpy.float64]) -> object
vectorized_func(arg0: numpy.ndarray[numpy.int32], arg1: numpy.ndarray[numpy.float32], arg2: numpy.ndarray[numpy.float64]) -> Any
"""
)

Expand Down Expand Up @@ -218,7 +218,7 @@ def test_passthrough_arguments(doc):
"arg6: numpy.ndarray[numpy.float64]",
]
)
+ ") -> object"
+ ") -> Any"
)

b = np.array([[10, 20, 30]], dtype="float64")
Expand Down
4 changes: 4 additions & 0 deletions tests/test_sequences_and_iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ def __len__(self):
assert m.sequence_length("hello") == 5


def test_sequence_doc():
assert m.sequence_length.__doc__.strip() == "sequence_length(arg0: Sequence) -> int"


def test_map_iterator():
sm = m.StringMap({"hi": "bye", "black": "white"})
assert sm["hi"] == "bye"
Expand Down
Loading