Describe the bug
simple_parsing silently produces a nested (corrupted) result when a list-annotated dataclass field uses action="append", instead of raising or producing a flat list.
To Reproduce
import dataclasses
import simple_parsing
@dataclasses.dataclass
class Args:
header: list[str] = simple_parsing.field(default_factory=list, action="append")
print(simple_parsing.parse(Args, args=["--header", "Auth", "--header", "Accept"]))
Expected behavior
Args(header=['Auth', 'Accept'])
Actual behavior
Args(header=[['Auth'], ['Accept']])
Desktop (please complete the following information):
- Version: 0.1.9
- Python version: 3.14.6
Additional context
Root cause: In simple_parsing/wrappers/field_wrapper.py, the is_list branch that builds add_argument kwargs unconditionally sets nargs="*", regardless of the requested action.
That's correct for the default store action (nargs="*" collects all tokens from one occurrence into the list), but wrong for action="append": each occurrence should be parsed as a single element, and AppendAction appends that element to a running list.
Because nargs="*" is still forced, each single --header Auth occurrence gets bundled into its own one-item list (["Auth"]) before AppendAction appends it, yielding a list of one-item lists.
No error is raised, so this fails silently.
Confirmed workaround: explicitly passing nargs=None overrides the bad default and produces the correct flat list:
header: list[str] = simple_parsing.field(default_factory=list, action="append", nargs=None)
This suggests the fix is for the is_list branch to skip (or set differently) nargs="*" when action is "append" (and possibly "extend").
Describe the bug
simple_parsingsilently produces a nested (corrupted) result when alist-annotated dataclass field usesaction="append", instead of raising or producing a flat list.To Reproduce
Expected behavior
Args(header=['Auth', 'Accept'])Actual behavior
Args(header=[['Auth'], ['Accept']])Desktop (please complete the following information):
Additional context
Root cause: In
simple_parsing/wrappers/field_wrapper.py, theis_listbranch that buildsadd_argumentkwargs unconditionally setsnargs="*", regardless of the requestedaction.That's correct for the default
storeaction (nargs="*" collects all tokens from one occurrence into the list), but wrong foraction="append": each occurrence should be parsed as a single element, andAppendActionappends that element to a running list.Because
nargs="*"is still forced, each single--header Authoccurrence gets bundled into its own one-item list (["Auth"]) beforeAppendActionappends it, yielding a list of one-item lists.No error is raised, so this fails silently.
Confirmed workaround: explicitly passing
nargs=Noneoverrides the bad default and produces the correct flat list:This suggests the fix is for the
is_listbranch to skip (or set differently)nargs="*"whenactionis"append"(and possibly"extend").