Skip to content

Commit

Permalink
Use annotated for array (#4679)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored May 25, 2023
1 parent 8e1f9d5 commit d0232b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions include/pybind11/stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@ struct array_caster {
}

PYBIND11_TYPE_CASTER(ArrayType,
const_name("List[") + value_conv::name
const_name<Resizable>(const_name(""), const_name("Annotated["))
+ const_name("List[") + value_conv::name + const_name("]")
+ const_name<Resizable>(const_name(""),
const_name("[") + const_name<Size>()
+ const_name("]"))
+ const_name("]"));
const_name(", FixedSize(")
+ const_name<Size>() + const_name(")]")));
};

template <typename Type, size_t Size>
Expand Down
7 changes: 5 additions & 2 deletions tests/test_stl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit d0232b1

Please sign in to comment.