Skip to content

Commit 2e382c0

Browse files
committed
Updated array_caster to match numpy/eigen typing.Annotated stlye
1 parent 756d055 commit 2e382c0

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

include/pybind11/stl.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,12 @@ struct array_caster {
479479
using cast_op_type = movable_cast_op_type<T_>;
480480

481481
static constexpr auto name
482-
= const_name<Resizable>(const_name(""), const_name("Annotated["))
482+
= const_name<Resizable>(const_name(""), const_name("typing.Annotated["))
483483
+ io_name("collections.abc.Sequence", "list") + const_name("[") + value_conv::name
484484
+ const_name("]")
485-
+ const_name<Resizable>(
486-
const_name(""), const_name(", FixedSize(") + const_name<Size>() + const_name(")]"));
485+
+ const_name<Resizable>(const_name(""),
486+
const_name(", \"FixedSize(") + const_name<Size>()
487+
+ const_name(")\"]"));
487488
};
488489

489490
template <typename Type, size_t Size>

tests/test_stl.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ def test_array(doc):
4444
assert m.load_array(lst)
4545
assert m.load_array(tuple(lst))
4646

47-
assert doc(m.cast_array) == "cast_array() -> Annotated[list[int], FixedSize(2)]"
47+
assert (
48+
doc(m.cast_array)
49+
== 'cast_array() -> typing.Annotated[list[int], "FixedSize(2)"]'
50+
)
4851
assert (
4952
doc(m.load_array)
50-
== "load_array(arg0: Annotated[collections.abc.Sequence[int], FixedSize(2)]) -> bool"
53+
== 'load_array(arg0: typing.Annotated[collections.abc.Sequence[int], "FixedSize(2)"]) -> bool'
5154
)
5255

5356

0 commit comments

Comments
 (0)