Skip to content

Commit 80a9086

Browse files
committed
Updated array_caster to match numpy/eigen typing.Annotated stlye
1 parent 872f9ff commit 80a9086

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

include/pybind11/stl.h

Lines changed: 4 additions & 3 deletions
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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ def test_array(doc):
4545
assert m.load_array(lst)
4646
assert m.load_array(tuple(lst))
4747

48-
assert doc(m.cast_array) == "cast_array() -> Annotated[list[int], FixedSize(2)]"
48+
assert (
49+
doc(m.cast_array)
50+
== 'cast_array() -> typing.Annotated[list[int], "FixedSize(2)"]'
51+
)
4952
assert (
5053
doc(m.load_array)
51-
== "load_array(arg0: Annotated[collections.abc.Sequence[typing.SupportsInt], FixedSize(2)]) -> bool"
54+
== 'load_array(arg0: typing.Annotated[collections.abc.Sequence[typing.SupportsInt], "FixedSize(2)"]) -> bool'
5255
)
5356

5457

0 commit comments

Comments
 (0)