Skip to content

fix: action="append" on list-typed fields no longer wraps each value in an extra list - #367

Draft
lebrice with Copilot wants to merge 3 commits into
masterfrom
copilot/fix-append-nested-list-issue
Draft

fix: action="append" on list-typed fields no longer wraps each value in an extra list#367
lebrice with Copilot wants to merge 3 commits into
masterfrom
copilot/fix-append-nested-list-issue

Conversation

Copilot AI commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

When a list-annotated field uses action="append", simple_parsing was unconditionally setting nargs="*", causing each --flag value occurrence to be collected into a one-item list before being appended — silently producing [["Auth"], ["Accept"]] instead of ["Auth", "Accept"].

Changes

  • simple_parsing/wrappers/field_wrapper.py — In the is_list branch of get_arg_options(), skip the nargs="*" override when action == "append". With nargs unset, argparse correctly treats each occurrence as a single value and appends it directly.
  • test/test_custom_args.py — Added test_append_action_on_list_field as a regression test, and test_extend_action_on_list_field to verify action="extend" (which correctly retains nargs="*") continues to work.
@dataclasses.dataclass
class Args:
    header: list[str] = simple_parsing.field(default_factory=list, action="append")

simple_parsing.parse(Args, args=["--header", "Auth", "--header", "Accept"])
# Before: Args(header=[['Auth'], ['Accept']])
# After:  Args(header=['Auth', 'Accept'])

Copilot AI and others added 2 commits August 16, 2026 12:23
Co-authored-by: lebrice <13387299+lebrice@users.noreply.github.com>
Co-authored-by: lebrice <13387299+lebrice@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix append action causing nested list in dataclasses fix: action="append" on list-typed fields no longer wraps each value in an extra list Aug 16, 2026
Copilot AI requested a review from lebrice August 16, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

action="append" on a list-typed field wraps each appended value in an extra list

2 participants