Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): remove newlines from docstring signature #4735

Merged
merged 30 commits into from
Aug 15, 2023
Merged
Changes from 6 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c89e5b2
Remove newlines from docstring signature
JeanElsner Jul 8, 2023
214b200
Jean/dev (#1)
JeanElsner Jul 8, 2023
99cd8d0
style: pre-commit fixes
pre-commit-ci[bot] Jul 8, 2023
f795b7e
Don't use std::find_if for C++ 11 compatibility
JeanElsner Jul 8, 2023
9640613
Avoid implicit char to bool conversion
JeanElsner Jul 8, 2023
293e6e2
Merge branch 'pybind:master' into jean/patch/argval
JeanElsner Jul 21, 2023
d8e7d2d
Test default arguments for line breaks
JeanElsner Jul 24, 2023
418bdef
style: pre-commit fixes
pre-commit-ci[bot] Jul 24, 2023
4521195
Separate Eigen tests
JeanElsner Jul 24, 2023
d47aa39
style: pre-commit fixes
pre-commit-ci[bot] Jul 24, 2023
7a9382a
Fix merge
JeanElsner Jul 24, 2023
15196d1
Merge branch 'pybind:master' into jean/patch/argval
JeanElsner Jul 24, 2023
5d7e555
Try importing numpy
JeanElsner Jul 29, 2023
a2d675f
Avoid unreferenced variable in catch block
JeanElsner Jul 29, 2023
035a044
style: pre-commit fixes
pre-commit-ci[bot] Jul 29, 2023
19a8d51
Update squash function
JeanElsner Aug 7, 2023
122e15a
Reduce try block
JeanElsner Aug 7, 2023
e6be9d5
Additional test cases
JeanElsner Aug 7, 2023
1b5a3d7
style: pre-commit fixes
pre-commit-ci[bot] Aug 7, 2023
4c844d5
Merge branch 'pybind:master' into jean/patch/argval
JeanElsner Aug 7, 2023
9918f22
Put statement inside braces
JeanElsner Aug 7, 2023
25c9657
Move string into function body
JeanElsner Aug 7, 2023
0ea0a13
Rename repr for better readability. Make constr explicit.
JeanElsner Aug 7, 2023
a2add0d
Add multiline string default argument test case
JeanElsner Aug 7, 2023
1a9dd7b
style: pre-commit fixes
pre-commit-ci[bot] Aug 7, 2023
d53892c
Add std namespace, do not modify string repr
JeanElsner Aug 8, 2023
9cefda8
Test for all space chars, test str repr not modified
JeanElsner Aug 8, 2023
68c5643
Merge branch 'pybind:master' into jean/patch/argval
JeanElsner Aug 8, 2023
d3885da
Merge branch 'pybind:master' into jean/patch/argval
JeanElsner Aug 14, 2023
b391386
Merge branch 'pybind:master' into jean/patch/argval
JeanElsner Aug 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,43 @@ PYBIND11_WARNING_DISABLE_MSVC(4127)

PYBIND11_NAMESPACE_BEGIN(detail)

inline std::string replaceNewlinesAndSquash(const char *text) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use camel-case I think. Could you please use the_prevailing_underscore_style for the function name and the variable names in this function?

std::string result;

// Replace newlines with spaces and squash consecutive spaces
while (*text != '\0') {
if (*text == '\n') {
result += ' ';
while (*(text + 1) == ' ') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to reuse the same list of whitespace characters as below?

++text;
}
} else {
result += *text;
}
++text;
}

// Strip leading spaces
size_t firstNonSpace = result.find_first_not_of(" \t\n\r\f\v");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move the string of whitespace characters to a constant and reuse?


if (firstNonSpace != std::string::npos) {
result.erase(0, firstNonSpace);
} else {
result.clear();
}

// Strip trailing spaces
size_t lastNonSpace = result.find_last_not_of(" \t\n\r\f\v");

if (lastNonSpace != std::string::npos) {
result.erase(lastNonSpace + 1);
} else {
result.clear();
}

return result;
}

// Apply all the extensions translators from a list
// Return true if one of the translators completed without raising an exception
// itself. Return of false indicates that if there are other translators
Expand Down Expand Up @@ -424,7 +461,7 @@ class cpp_function : public function {
// Write default value if available.
if (!is_starred && arg_index < rec->args.size() && rec->args[arg_index].descr) {
signature += " = ";
signature += rec->args[arg_index].descr;
signature += detail::replaceNewlinesAndSquash(rec->args[arg_index].descr);
}
// Separator for positional-only arguments (placed after the
// argument, rather than before like *
Expand Down