mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 14:45:12 +00:00
* Bug fix: `result[0]` called if `result.empty()` * Add unit test that fails without the fix.
This commit is contained in:
parent
8c7b8dd0ae
commit
d06d53694a
@ -57,11 +57,13 @@ inline std::string replace_newlines_and_squash(const char *text) {
|
|||||||
std::string result(text);
|
std::string result(text);
|
||||||
bool previous_is_whitespace = false;
|
bool previous_is_whitespace = false;
|
||||||
|
|
||||||
// Do not modify string representations
|
if (result.size() >= 2) {
|
||||||
char first_char = result[0];
|
// Do not modify string representations
|
||||||
char last_char = result[result.size() - 1];
|
char first_char = result[0];
|
||||||
if (first_char == last_char && first_char == '\'') {
|
char last_char = result[result.size() - 1];
|
||||||
return result;
|
if (first_char == last_char && first_char == '\'') {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
result.clear();
|
result.clear();
|
||||||
|
|
||||||
|
@ -85,6 +85,8 @@ TEST_SUBMODULE(kwargs_and_defaults, m) {
|
|||||||
"kw_lb_func7",
|
"kw_lb_func7",
|
||||||
[](const std::string &) {},
|
[](const std::string &) {},
|
||||||
py::arg("str_arg") = "First line.\n Second line.");
|
py::arg("str_arg") = "First line.\n Second line.");
|
||||||
|
m.def(
|
||||||
|
"kw_lb_func8", [](const CustomRepr &) {}, py::arg("custom") = CustomRepr(""));
|
||||||
|
|
||||||
// test_args_and_kwargs
|
// test_args_and_kwargs
|
||||||
m.def("args_function", [](py::args args) -> py::tuple {
|
m.def("args_function", [](py::args args) -> py::tuple {
|
||||||
|
@ -55,6 +55,10 @@ def test_function_signatures(doc):
|
|||||||
doc(m.kw_lb_func7)
|
doc(m.kw_lb_func7)
|
||||||
== "kw_lb_func7(str_arg: str = 'First line.\\n Second line.') -> None"
|
== "kw_lb_func7(str_arg: str = 'First line.\\n Second line.') -> None"
|
||||||
)
|
)
|
||||||
|
assert (
|
||||||
|
doc(m.kw_lb_func8)
|
||||||
|
== "kw_lb_func8(custom: m.kwargs_and_defaults.CustomRepr = ) -> None"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_named_arguments():
|
def test_named_arguments():
|
||||||
|
Loading…
Reference in New Issue
Block a user