[issue15906] argparse add_argument() confusing behavior when type=str, default=

Chris Jerdonek report at bugs.python.org
Wed Sep 12 21:49:05 CEST 2012


Chris Jerdonek added the comment:

Thanks for committing the change.  However--

+    def test_no_double_type_conversion_of_default(self):
+        def extend(str_to_convert):
+            return str_to_convert + '*'
+
+        parser = argparse.ArgumentParser()
+        parser.add_argument('--test', type=extend, default='*')
+        args = parser.parse_args([])
+        # The test argument will be two stars, one coming from the default
+        # value and one coming from the type conversion being called exactly
+        # once.
+        self.assertEqual(NS(test='**'), args)

This was actually my concern, that the type conversion would be applied twice, and the reason for my suggesting the test.  This expected value is not the one we want, because it shows that the argument is getting "double converted," though the test is supposed to assert that double conversion doesn't take place.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15906>
_______________________________________


More information about the Python-bugs-list mailing list