Skip to content
Merged
Changes from 1 commit
Commits
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
13 changes: 13 additions & 0 deletions docs/api/gen_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,25 @@ def gen_functions_args_str(node):
str_args_list = []
if isinstance(node, ast.FunctionDef):
# 'args', 'defaults', 'kw_defaults', 'kwarg', 'kwonlyargs', 'posonlyargs', 'vararg'
if node.args.posonlyargs is not None:
for arg in node.args.posonlyargs:
if not arg.arg == "self":
str_args_list.append(arg.arg)
str_args_list.append("/")

for arg in node.args.args:
if not arg.arg == "self":
str_args_list.append(arg.arg)

defarg_ind_start = len(str_args_list) - len(node.args.defaults)
if node.args.posonlyargs is not None and len(node.args.defaults) > len(
node.args.args
):
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The calculation of defarg_ind_start adjustment is unclear. The logic assumes defaults overflow into posonlyargs territory by exactly one position, but this may not account for all edge cases. Consider adding a comment explaining the mathematical relationship between defaults, args, posonlyargs, and the '/' separator position.

Suggested change
defarg_ind_start = len(str_args_list) - len(node.args.defaults)
if node.args.posonlyargs is not None and len(node.args.defaults) > len(
node.args.args
):
# Calculate the starting index in str_args_list where default values should be applied.
# The list str_args_list contains argument names in the order: posonlyargs (if any), '/', args.
# node.args.defaults contains default values for the last N positional arguments (posonlyargs + args).
# The defaults are applied to the last N arguments, which may include both args and posonlyargs.
# If the number of defaults exceeds the number of args, the extra defaults apply to posonlyargs.
# The '/' separator is present if posonlyargs exist, and must be skipped when assigning defaults.
defarg_ind_start = len(str_args_list) - len(node.args.defaults)
if node.args.posonlyargs is not None and len(node.args.defaults) > len(
node.args.args
):
# If defaults overflow into posonlyargs, adjust the start index to skip the '/' separator.

Copilot uses AI. Check for mistakes.
defarg_ind_start -= 1

for defarg_ind in range(len(node.args.defaults)):
if str_args_list[defarg_ind_start + defarg_ind] == "/":
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

Potential IndexError if defarg_ind_start + defarg_ind exceeds the list bounds. This can occur when there are more defaults than combined posonlyargs and args. Add a bounds check before accessing the list element.

Copilot uses AI. Check for mistakes.
defarg_ind_start += 1
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

This check is inside the loop and modifies defarg_ind_start each iteration, which can cause incorrect indexing for subsequent defaults. The slash skip should only occur once when first encountered. Consider moving this check outside the loop or using a flag to ensure it only executes once.

Suggested change
for defarg_ind in range(len(node.args.defaults)):
if str_args_list[defarg_ind_start + defarg_ind] == "/":
defarg_ind_start += 1
# Skip the "/" marker only once if it is at the start index
if (
defarg_ind_start < len(str_args_list)
and str_args_list[defarg_ind_start] == "/"
):
defarg_ind_start += 1
for defarg_ind in range(len(node.args.defaults)):

Copilot uses AI. Check for mistakes.
if isinstance(node.args.defaults[defarg_ind], ast.Name):
str_args_list[defarg_ind_start + defarg_ind] += "=" + str(
node.args.defaults[defarg_ind].id
Expand Down