summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_argparse.py
diff options
context:
space:
mode:
authorAdam Schwalm <adamschwalm@gmail.com>2021-09-18 04:20:31 (GMT)
committerGitHub <noreply@github.com>2021-09-18 04:20:31 (GMT)
commita6e8db5e8e6780411db749d404715dbe021647c7 (patch)
treedd2b82a52745e2f764788b613fc928670c01f026 /Lib/test/test_argparse.py
parentaf08f1ba40505bf1380c08b57ba4e0b8969a8358 (diff)
downloadcpython-a6e8db5e8e6780411db749d404715dbe021647c7.zip
cpython-a6e8db5e8e6780411db749d404715dbe021647c7.tar.gz
cpython-a6e8db5e8e6780411db749d404715dbe021647c7.tar.bz2
bpo-45235: Fix argparse overrides namespace with subparser defaults (GH-28420)
Diffstat (limited to 'Lib/test/test_argparse.py')
-rw-r--r--Lib/test/test_argparse.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index d369d0f..9926910 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -3079,6 +3079,12 @@ class TestSetDefaults(TestCase):
xparser.set_defaults(foo=2)
self.assertEqual(NS(foo=2), parser.parse_args(['X']))
+ def test_set_defaults_on_subparser_with_namespace(self):
+ parser = argparse.ArgumentParser()
+ xparser = parser.add_subparsers().add_parser('X')
+ xparser.set_defaults(foo=1)
+ self.assertEqual(NS(foo=2), parser.parse_args(['X'], NS(foo=2)))
+
def test_set_defaults_same_as_add_argument(self):
parser = ErrorRaisingArgumentParser()
parser.set_defaults(w='W', x='X', y='Y', z='Z')