mirror of
https://github.com/pybind/pybind11.git
synced 2026-06-08 15:29:45 +00:00
feat(types): adds support for TypeGuard and TypeIs (#5194)
* Adds support for TypeGuard and TypeIs * style: pre-commit fixes --------- Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
b5ec7c7174
commit
2be85c6041
@@ -892,8 +892,15 @@ TEST_SUBMODULE(pytypes, m) {
|
||||
return list;
|
||||
});
|
||||
|
||||
m.def("annotate_type_guard", [](py::object &o) -> py::typing::TypeGuard<py::str> {
|
||||
return py::isinstance<py::str>(o);
|
||||
});
|
||||
m.def("annotate_type_is",
|
||||
[](py::object &o) -> py::typing::TypeIs<py::str> { return py::isinstance<py::str>(o); });
|
||||
|
||||
m.def("annotate_no_return", []() -> py::typing::NoReturn { throw 0; });
|
||||
m.def("annotate_never", []() -> py::typing::Never { throw 0; });
|
||||
|
||||
m.def("annotate_optional_to_object",
|
||||
[](py::typing::Optional<int> &o) -> py::object { return o; });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user