Issue #18920: argparse's default version action (for -v, --version) should
output to stdout, matching the 'python -v' Reported by Wolfgang Maier
This commit is contained in:
parent
309836c5c8
commit
cdac551675
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
-----
|
||||
|
||||
|
|
Loading…
Reference in New Issue