File tree 3 files changed +16
-0
lines changed
3 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,13 @@ struct handle_type_name<typing::Tuple<>> {
79
79
static constexpr auto name = const_name(" tuple[()]" );
80
80
};
81
81
82
+ template <typename T>
83
+ struct handle_type_name <typing::Tuple<T, ellipsis>> {
84
+ // PEP 484 specifies this syntax for a variable-length tuple
85
+ static constexpr auto name
86
+ = const_name(" tuple[" ) + make_caster<T>::name + const_name(" , ...]" );
87
+ };
88
+
82
89
template <typename K, typename V>
83
90
struct handle_type_name <typing::Dict<K, V>> {
84
91
static constexpr auto name = const_name(" dict[" ) + make_caster<K>::name + const_name(" , " )
Original file line number Diff line number Diff line change @@ -825,6 +825,8 @@ TEST_SUBMODULE(pytypes, m) {
825
825
826
826
m.def (" annotate_tuple_float_str" , [](const py::typing::Tuple<py::float_, py::str> &) {});
827
827
m.def (" annotate_tuple_empty" , [](const py::typing::Tuple<> &) {});
828
+ m.def (" annotate_tuple_variable_length" ,
829
+ [](const py::typing::Tuple<py::float_, py::ellipsis> &) {});
828
830
m.def (" annotate_dict_str_int" , [](const py::typing::Dict<py::str, int > &) {});
829
831
m.def (" annotate_list_int" , [](const py::typing::List<int > &) {});
830
832
m.def (" annotate_set_str" , [](const py::typing::Set<std::string> &) {});
Original file line number Diff line number Diff line change @@ -911,6 +911,13 @@ def test_tuple_empty_annotations(doc):
911
911
)
912
912
913
913
914
+ def test_tuple_variable_length_annotations (doc ):
915
+ assert (
916
+ doc (m .annotate_tuple_variable_length )
917
+ == "annotate_tuple_variable_length(arg0: tuple[float, ...]) -> None"
918
+ )
919
+
920
+
914
921
def test_dict_annotations (doc ):
915
922
assert (
916
923
doc (m .annotate_dict_str_int )
You can’t perform that action at this time.
0 commit comments