mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
Fix debugging output for nameless py::arg_v annotations (#648)
* Fix debugging output for nameless py::arg annotations This fixes a couple bugs with nameless py::arg() (introduced in #634) annotations: - the argument name was being used in debug mode without checking that it exists (which would result in the std::string construction throwing an exception for being invoked with a nullptr) - the error output says "keyword arguments", but py::arg_v() can now also be used for positional argument defaults. - the debugging output "in function named 'blah'" was overly verbose: changed it to just "in function 'blah'". * Fix missing space in debug test string * Moved tests from issues to methods_and_attributes
This commit is contained in:
committed by
Wenzel Jakob
parent
93cc4bd6d7
commit
1eaacd19f6
@@ -150,6 +150,9 @@ public:
|
||||
};
|
||||
}}
|
||||
|
||||
/// Issue/PR #648: bad arg default debugging output
|
||||
class NotRegistered {};
|
||||
|
||||
test_initializer methods_and_attributes([](py::module &m) {
|
||||
py::class_<ExampleMandA>(m, "ExampleMandA")
|
||||
.def(py::init<>())
|
||||
@@ -270,4 +273,18 @@ test_initializer methods_and_attributes([](py::module &m) {
|
||||
m.def("floats_preferred", [](double f) { return 0.5 * f; }, py::arg("f"));
|
||||
m.def("floats_only", [](double f) { return 0.5 * f; }, py::arg("f").noconvert());
|
||||
|
||||
/// Issue/PR #648: bad arg default debugging output
|
||||
#if !defined(NDEBUG)
|
||||
m.attr("debug_enabled") = true;
|
||||
#else
|
||||
m.attr("debug_enabled") = false;
|
||||
#endif
|
||||
m.def("bad_arg_def_named", []{
|
||||
auto m = py::module::import("pybind11_tests.issues");
|
||||
m.def("should_fail", [](int, NotRegistered) {}, py::arg(), py::arg("a") = NotRegistered());
|
||||
});
|
||||
m.def("bad_arg_def_unnamed", []{
|
||||
auto m = py::module::import("pybind11_tests.issues");
|
||||
m.def("should_fail", [](int, NotRegistered) {}, py::arg(), py::arg() = NotRegistered());
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user