Skip to content

Empty tuple default value not supported #589

@MiguelMonteiro

Description

@MiguelMonteiro

🐛 Bug report

Empty tuples are not supported by the parser.

To reproduce

from dataclasses import dataclass

from jsonargparse import ArgumentParser


@dataclass
class TestCfg:
    a: tuple[int, ...] = ()


if __name__ == "__main__":
    parser = ArgumentParser(description="CLI for training models", exit_on_error=False)
    parser.add_argument("test", type=TestCfg)
    args = parser.parse_args()
    print(args)

Running the following program without passing any arguments or by passing an empty list/tuple "[]" results in the following error:

argparse.ArgumentError: Validation failed: Parser key "test.a":
  Expected a non-empty tuple. Got value: []

Expected behavior

To be able to parse empty tuples without errors.

Environment

  • jsonargparse version: 4.33.1
  • Python version: 3.10
  • How jsonargparse was installed: pip
  • OS: MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions