Update no_* argument (HfArgumentParser) (#13865)

* update no_* argument

Changes the order so that the no_* argument is created after the original argument AND sets the default for this no_* argument to False

* import copy

* update test

* make style

* Use kwargs to set default=False

* make style
This commit is contained in:
Bram Vanroy
2021-10-04 22:28:52 +02:00
committed by GitHub
parent cc0a415e2f
commit 12b4d66a80
2 changed files with 18 additions and 3 deletions

View File

@@ -126,8 +126,10 @@ class HfArgumentParserTest(unittest.TestCase):
expected = argparse.ArgumentParser()
expected.add_argument("--foo", type=string_to_bool, default=False, const=True, nargs="?")
expected.add_argument("--no_baz", action="store_false", dest="baz")
expected.add_argument("--baz", type=string_to_bool, default=True, const=True, nargs="?")
# A boolean no_* argument always has to come after its "default: True" regular counter-part
# and its default must be set to False
expected.add_argument("--no_baz", action="store_false", default=False, dest="baz")
expected.add_argument("--opt", type=string_to_bool, default=None)
self.argparsersEqual(parser, expected)