From d0232b119f5f0cf2bf6cecacaf099c301c811ca8 Mon Sep 17 00:00:00 2001 From: "T.Yamada" Date: Thu, 25 May 2023 13:39:36 +0900 Subject: [PATCH] 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 Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- include/pybind11/stl.h | 8 ++++---- tests/test_stl.py | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/pybind11/stl.h b/include/pybind11/stl.h index 84c5171081..f39f44f7c9 100644 --- a/include/pybind11/stl.h +++ b/include/pybind11/stl.h @@ -273,11 +273,11 @@ struct array_caster { } PYBIND11_TYPE_CASTER(ArrayType, - const_name("List[") + value_conv::name + const_name(const_name(""), const_name("Annotated[")) + + const_name("List[") + value_conv::name + const_name("]") + const_name(const_name(""), - const_name("[") + const_name() - + const_name("]")) - + const_name("]")); + const_name(", FixedSize(") + + const_name() + const_name(")]"))); }; template diff --git a/tests/test_stl.py b/tests/test_stl.py index 2d9dcc89f1..8a614f8b87 100644 --- a/tests/test_stl.py +++ b/tests/test_stl.py @@ -39,8 +39,11 @@ def test_array(doc): assert m.load_array(lst) assert m.load_array(tuple(lst)) - assert doc(m.cast_array) == "cast_array() -> List[int[2]]" - assert doc(m.load_array) == "load_array(arg0: List[int[2]]) -> bool" + assert doc(m.cast_array) == "cast_array() -> Annotated[List[int], FixedSize(2)]" + assert ( + doc(m.load_array) + == "load_array(arg0: Annotated[List[int], FixedSize(2)]) -> bool" + ) def test_valarray(doc):