Provide better type hints for a variety of generic types (#4259)

* Provide better type hints for a variety of generic types

* Makes better documentation
* tuple, dict, list, set, function

* Move to py::typing

* style: pre-commit fixes

* Update copyright line with correct year and actual author. The author information was copy-pasted from the git log output.

---------

Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Dustin Spicuzza
2023-08-04 01:48:57 -04:00
committed by GitHub
parent 9ad7e827a2
commit f8703154ec
6 changed files with 174 additions and 1 deletions

View File

@@ -7,6 +7,8 @@
BSD-style license that can be found in the LICENSE file.
*/
#include <pybind11/typing.h>
#include "pybind11_tests.h"
#include <utility>
@@ -820,4 +822,12 @@ TEST_SUBMODULE(pytypes, m) {
a >>= b;
return a;
});
m.def("annotate_tuple_float_str", [](const py::typing::Tuple<py::float_, py::str> &) {});
m.def("annotate_tuple_empty", [](const py::typing::Tuple<> &) {});
m.def("annotate_dict_str_int", [](const py::typing::Dict<py::str, int> &) {});
m.def("annotate_list_int", [](const py::typing::List<int> &) {});
m.def("annotate_set_str", [](const py::typing::Set<std::string> &) {});
m.def("annotate_fn",
[](const py::typing::Callable<int(py::typing::List<py::str>, py::str)> &) {});
}