#9351: set_defaults on subparser is no longer ignored if set on parent.
Before, if a default was set on the parent parser, any default for that
variable set via set_defaults on a subparser would be ignored. Now
the subparser set_defaults is honored.
Patch by Jyrki Pullianinen.
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index b615722..98ccfe4 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -2795,6 +2795,13 @@
parser = ErrorRaisingArgumentParser(parents=[parent])
self.assertEqual(NS(x='foo'), parser.parse_args([]))
+ def test_set_defaults_on_parent_and_subparser(self):
+ parser = argparse.ArgumentParser()
+ xparser = parser.add_subparsers().add_parser('X')
+ parser.set_defaults(foo=1)
+ xparser.set_defaults(foo=2)
+ self.assertEqual(NS(foo=2), parser.parse_args(['X']))
+
def test_set_defaults_same_as_add_argument(self):
parser = ErrorRaisingArgumentParser()
parser.set_defaults(w='W', x='X', y='Y', z='Z')