lebrice / SimpleParsing

Simple, Elegant, Typed Argument Parsing with argparse
MIT License
410 stars 51 forks source link

Hangup when trying to call `parse_args` second time #7

Closed dmitriy-serdyuk closed 4 years ago

dmitriy-serdyuk commented 4 years ago

Describe the bug Script hangs up when trying to call parser.parse_args() two times. It doesn't usually happen in real code, but I think exception would be better than hangup.

To Reproduce

from dataclasses import dataclass
import simple_parsing

parser = simple_parsing.ArgumentParser()
parser.add_argument("--foo", type=int, default=123, help="foo help string")

@dataclass
class Options:
    """ Help string for this group of command-line arguments """
    log_dir: str                # Help string for a required str argument    
    learning_rate: float = 1e-4 # Help string for a float argument

parser.add_arguments(Options, dest="options")

args = parser.parse_args("--log_dir logs --foo 123".split())
args = parser.parse_args("--log_dir logs --foo 123".split())

Expected behavior Does not hang up.

lebrice commented 4 years ago

Fixed by https://github.com/lebrice/SimpleParsing/pull/9#issue-361282316

Instead of raising an Exception, I actually just parse the second set of arguments, since that is what argparse seems to do in such a case. I'll add some more complicated tests, but the simple cases seem solved for now.