]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #18920: argparse's default version action (for -v, --version) should
authorEli Bendersky <eliben@gmail.com>
Fri, 6 Sep 2013 13:49:15 +0000 (06:49 -0700)
committerEli Bendersky <eliben@gmail.com>
Fri, 6 Sep 2013 13:49:15 +0000 (06:49 -0700)
output to stdout, matching the 'python -v'

Reported by Wolfgang Maier

Lib/argparse.py
Lib/test/test_argparse.py
Misc/NEWS

index 5ff755c84ab207bbbf16886ccbd1445ef6262dfc..9520e0ea7c67cb9d74fc8a8a74c54698b18a14cc 100644 (file)
@@ -1037,7 +1037,8 @@ class _VersionAction(Action):
             version = parser.version
         formatter = parser._get_formatter()
         formatter.add_text(version)
-        parser.exit(message=formatter.format_help())
+        parser._print_message(formatter.format_help(), _sys.stdout)
+        parser.exit()
 
 
 class _SubParsersAction(Action):
index 00cde2ed5cc953c2960a22f780d49176c42c59c2..c10c5909bf3e2e165df3f747c6ecb6a566c789f1 100644 (file)
@@ -4359,7 +4359,7 @@ class TestOptionalsHelpVersionActions(TestCase):
     def test_version_format(self):
         parser = ErrorRaisingArgumentParser(prog='PPP')
         parser.add_argument('-v', '--version', action='version', version='%(prog)s 3.5')
-        msg = self._get_error(parser.parse_args, ['-v']).stderr
+        msg = self._get_error(parser.parse_args, ['-v']).stdout
         self.assertEqual('PPP 3.5\n', msg)
 
     def test_version_no_help(self):
@@ -4372,7 +4372,7 @@ class TestOptionalsHelpVersionActions(TestCase):
     def test_version_action(self):
         parser = ErrorRaisingArgumentParser(prog='XXX')
         parser.add_argument('-V', action='version', version='%(prog)s 3.7')
-        msg = self._get_error(parser.parse_args, ['-V']).stderr
+        msg = self._get_error(parser.parse_args, ['-V']).stdout
         self.assertEqual('XXX 3.7\n', msg)
 
     def test_no_help(self):
index c69110f1f827f2da23d6be446a5963e25e430c7e..67788c911eb2454c40b756664f748df538d02969 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -193,6 +193,9 @@ Library
   existing directory caused mkstemp and related APIs to fail instead of
   retrying. Report and fix by Vlad Shcherbina.
 
+- Issue #18920: argparse's default destination for the version action (-v,
+  --version) has also been changed to stdout, to match the Python executable.
+
 Tests
 -----