mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-19 22:39:09 +00:00
Make TypeErrors more informative when an optional header is missing
E.g. trying to convert a `list` to a `std::vector<int>` without including <pybind11/stl.h> will now raise an error with a note that suggests checking the headers. The note is only appended if `std::` is found in the function signature. This should only be the case when a header is missing. E.g. when stl.h is included, the signature would contain `List[int]` instead of `std::vector<int>` while using stl_bind.h would produce something like `MyVector`. Similarly for `std::map`/`Dict`, `complex`, `std::function`/`Callable`, etc. There's a possibility for false positives, but it's pretty low.
This commit is contained in:
@@ -114,4 +114,10 @@ PYBIND11_MODULE(pybind11_cross_module_tests, m) {
|
||||
// the same module (it would be an ODR violation). Therefore `bind_vector` of `bool`
|
||||
// is defined here and tested in `test_stl_binders.py`.
|
||||
py::bind_vector<std::vector<bool>>(m, "VectorBool");
|
||||
|
||||
// test_missing_header_message
|
||||
// The main module already includes stl.h, but we need to test the error message
|
||||
// which appears when this header is missing.
|
||||
m.def("missing_header_arg", [](std::vector<float>) { });
|
||||
m.def("missing_header_return", []() { return std::vector<float>(); });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user