Skip to content

Commit d0232b1

Browse files
cielavenirTaiju Yamadapre-commit-ci[bot]
authored
Use annotated for array (#4679)
* use Annotated for std::array docstring * add tests * fix test * style: pre-commit fixes * fix valarray annotation * style: pre-commit fixes * refix test * add FixedSize * style: pre-commit fixes * Update test_stl.py * style: pre-commit fixes --------- Co-authored-by: Taiju Yamada <taiju.yamada@mujin.co.jp> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 8e1f9d5 commit d0232b1

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

include/pybind11/stl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,11 @@ struct array_caster {
273273
}
274274

275275
PYBIND11_TYPE_CASTER(ArrayType,
276-
const_name("List[") + value_conv::name
276+
const_name<Resizable>(const_name(""), const_name("Annotated["))
277+
+ const_name("List[") + value_conv::name + const_name("]")
277278
+ const_name<Resizable>(const_name(""),
278-
const_name("[") + const_name<Size>()
279-
+ const_name("]"))
280-
+ const_name("]"));
279+
const_name(", FixedSize(")
280+
+ const_name<Size>() + const_name(")]")));
281281
};
282282

283283
template <typename Type, size_t Size>

tests/test_stl.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ def test_array(doc):
3939
assert m.load_array(lst)
4040
assert m.load_array(tuple(lst))
4141

42-
assert doc(m.cast_array) == "cast_array() -> List[int[2]]"
43-
assert doc(m.load_array) == "load_array(arg0: List[int[2]]) -> bool"
42+
assert doc(m.cast_array) == "cast_array() -> Annotated[List[int], FixedSize(2)]"
43+
assert (
44+
doc(m.load_array)
45+
== "load_array(arg0: Annotated[List[int], FixedSize(2)]) -> bool"
46+
)
4447

4548

4649
def test_valarray(doc):

0 commit comments

Comments
 (0)