lebrice / SimpleParsing

Simple, Elegant, Typed Argument Parsing with argparse
MIT License
428 stars 52 forks source link

Tuple parsing is incorrect - results in nested tuples #29

Closed MartinHowarth closed 4 years ago

MartinHowarth commented 4 years ago

Describe the bug This dataclass:

@dataclass
class MyCli:
    asdf: Tuple[str, ...]

gets parsed as: MyCli(asdf=(('asdf',), ('fgfh',))) but it should be: MyCli(asdf=('asdf', 'fgfh'))

This works correctly with List instead of Tuple however.

To Reproduce Run the following with arguments --asdf asdf fgfh

from simple_parsing import ArgumentParser
from dataclasses import dataclass
from typing import *

@dataclass
class MyCli:
    asdf: Tuple[str, ...]

parser = ArgumentParser()
parser.add_arguments(MyCli, dest="args")
args = parser.parse_args()
print(args.args)  # MyCli(asdf=(('asdf',), ('fgfh',)))
print(args.args.asdf)  # (('asdf',), ('fgfh',))
print(args.args.asdf[0])  # ('asdf',)

Expected behavior Should not result in each element of the tuple also being a single-element tuple.

lebrice commented 4 years ago

Thanks for posting this!