File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,13 @@ class Optional : public object {
8080 using object::object;
8181};
8282
83+ class NoReturn : public none {
84+ using none::none;
85+ };
86+
87+ class Never : public none {
88+ using none::none;
89+ };
8390#if defined(__cpp_nontype_template_parameter_class)
8491template <size_t N>
8592struct StringLiteral {
@@ -176,6 +183,15 @@ struct handle_type_name<typing::Optional<T>> {
176183 static constexpr auto name = const_name(" Optional[" ) + make_caster<T>::name + const_name(" ]" );
177184};
178185
186+ template <>
187+ struct handle_type_name <typing::NoReturn> {
188+ static constexpr auto name = const_name(" NoReturn" );
189+ };
190+
191+ template <>
192+ struct handle_type_name <typing::Never> {
193+ static constexpr auto name = const_name(" Never" );
194+ };
179195#if defined(__cpp_nontype_template_parameter_class)
180196template <typing::StringLiteral... Literals>
181197struct handle_type_name <typing::Literal<Literals...>> {
Original file line number Diff line number Diff line change @@ -891,6 +891,9 @@ TEST_SUBMODULE(pytypes, m) {
891891 list.append (py::none ());
892892 return list;
893893 });
894+
895+ m.def (" annotate_no_return" , []() -> py::typing::NoReturn { throw 0 ; });
896+ m.def (" annotate_never" , []() -> py::typing::Never { throw 0 ; });
894897 m.def (" annotate_optional_to_object" ,
895898 [](py::typing::Optional<int > &o) -> py::object { return o; });
896899
Original file line number Diff line number Diff line change @@ -991,6 +991,14 @@ def test_optional_annotations(doc):
991991 )
992992
993993
994+ def test_no_return_annotation (doc ):
995+ assert doc (m .annotate_no_return ) == "annotate_no_return() -> NoReturn"
996+
997+
998+ def test_never_annotation (doc ):
999+ assert doc (m .annotate_never ) == "annotate_never() -> Never"
1000+
1001+
9941002def test_optional_object_annotations (doc ):
9951003 assert (
9961004 doc (m .annotate_optional_to_object )
You can’t perform that action at this time.
0 commit comments