Skip to content

Commit 20c1855

Browse files
committed
Fixed false tokens in GetArgumentTokens when docstring contains ",".
1 parent 8fd9f01 commit 20c1855

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

cpp/pybind/docstring.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,12 @@ std::vector<std::string> FunctionDoc::GetArgumentTokens(
347347
str.replace(parenthesis_pos + 1, 0, ", ");
348348
}
349349

350+
// Ignore everything after last argument (right before ") ->")
351+
// Otherwise false argument matches might be found in docstrings
352+
std::size_t arrow_pos = str.rfind(") -> ");
353+
if (arrow_pos == std::string::npos) return {};
354+
str = str.substr(0, arrow_pos);
355+
350356
// Get start positions
351357
std::regex pattern("(, [A-Za-z_][A-Za-z\\d_]*:)");
352358
std::smatch res;
@@ -366,12 +372,7 @@ std::vector<std::string> FunctionDoc::GetArgumentTokens(
366372
for (size_t i = 0; i + 1 < argument_start_positions.size(); ++i) {
367373
argument_end_positions.push_back(argument_start_positions[i + 1] - 2);
368374
}
369-
std::size_t arrow_pos = str.rfind(") -> ");
370-
if (arrow_pos == std::string::npos) {
371-
return {};
372-
} else {
373-
argument_end_positions.push_back(arrow_pos);
374-
}
375+
argument_end_positions.push_back(arrow_pos);
375376

376377
std::vector<std::string> argument_tokens;
377378
for (size_t i = 0; i < argument_start_positions.size(); ++i) {

0 commit comments

Comments
 (0)