Skip to content

Commit a1056d6

Browse files
authored
Ensure docs option parsing does not drop final argument (#1545)
The custom options parser for experiment and analysis class documentation loops through the options methods' docstrings to pull out the documentation for the different options. This loop parsed the docstring into options by accumulating an option across multiple lines and then adding to the parsed set when it hit a less indented line. Starting with Python 3.13, the trailing whitespace of docstrings is stripped automatically. So the final newline that docstrings usually had is no longer present and a less indented line is never hit for the final option to be parsed, resulting in that option being dropped from the documentation. Here the loop was reworked to accumulate the options more eagerly so that the final option is not dropped.
1 parent ee44aa3 commit a1056d6

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

docs/_ext/custom_styles/option_parser.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -151,28 +151,33 @@ def _flatten_option_docs(
151151
return [], set()
152152

153153
indent = len(docstring_lines[line_ind]) - len(docstring_lines[line_ind].lstrip())
154-
tmp = ""
155154
parsed_lines = []
156155
added_args = set()
157-
for line in docstring_lines[line_ind:]:
158-
if line[indent:].startswith(" "):
156+
idx = line_ind
157+
while idx < len(docstring_lines):
158+
arg_entry = docstring_lines[idx]
159+
idx = idx + 1
160+
while idx < len(docstring_lines):
159161
# Remove linefeed and turn multi-line description into single-line
160-
tmp += " " + line.lstrip()
161-
else:
162-
if tmp:
163-
matched = _parameter_doc_regex.match(tmp)
164-
if not matched:
165-
raise ValueError(
166-
f"Option documentation '{tmp}' doesn't conform to the "
167-
"expected documentation style. "
168-
"Use '<name> (<type>): <description>' format."
169-
)
170-
opt_name = matched.group(1).strip()
171-
if target_args and opt_name in target_args:
172-
parsed_lines.append(tmp.lstrip())
173-
added_args.add(opt_name)
174-
# Start new line
175-
tmp = line
162+
if docstring_lines[idx][indent:].startswith(" "):
163+
arg_entry += " " + docstring_lines[idx].strip()
164+
idx += 1
165+
else:
166+
break
167+
if not arg_entry.strip():
168+
# Skip blank lines
169+
continue
170+
matched = _parameter_doc_regex.match(arg_entry)
171+
if not matched:
172+
raise ValueError(
173+
f"Option documentation '{arg_entry}' doesn't conform to the "
174+
"expected documentation style. "
175+
"Use '<name> (<type>): <description>' format."
176+
)
177+
opt_name = matched.group(1).strip()
178+
if target_args and opt_name in target_args:
179+
parsed_lines.append(arg_entry.lstrip())
180+
added_args.add(opt_name)
176181

177182
return parsed_lines, added_args
178183

0 commit comments

Comments
 (0)