classification
Title: argparse module version action
Type: behavior Stage: resolved
Components: Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: bethard, eli.bendersky, ezio.melotti, python-dev, serhiy.storchaka, wolma
Priority: normal Keywords: easy, patch

Created on 2013-09-04 12:30 by wolma, last changed 2013-09-06 13:57 by eli.bendersky. This issue is now closed.

Files
File name Uploaded Description Edit
issue18920.1.patch eli.bendersky, 2013-09-04 13:49
Messages (11)
msg196905 - (view) Author: Wolfgang Maier (wolma) * Date: 2013-09-04 12:30
Hi,
I just noticed that version output generated via the
**'version' action** of the **argparse** module
is routed to stderr. I'd expect regular output to go to stdout instead.
The current behavior also seems inconsistent to me because --help
prints to stdout.
Best,
Wolfgang
msg196908 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-09-04 13:17
Yes, it seems like an oversight to me. Printing --version to stdout is more customary (Python itself does it, and most other tools do too).

A question comes up about backwards compatibility. I would definitely not change it in 2.x - it's just not worth it. As for 3.x, should this go into 3.3 too or just 3.4?
msg196910 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-09-04 13:26
Only on 3.4.
Python prints the version on stdout since 3.4 -- before it used stderr:
3.3$ ./python -V 2> /dev/null
3.3$ ./python -V > /dev/null
Python 3.3.2+

3.4$ ./python -V 2> /dev/null
Python 3.4.0a1+
3.4$ ./python -V > /dev/null

This might also explain why argparse uses stderr (other modules/scripts in the stdlib might do the same too).
msg196911 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-09-04 13:34
On Wed, Sep 4, 2013 at 6:26 AM, Ezio Melotti <report@bugs.python.org> wrote:

>
> Ezio Melotti added the comment:
>
> Only on 3.4.
> Python prints the version on stdout since 3.4 -- before it used stderr:
> 3.3$ ./python -V 2> /dev/null
> 3.3$ ./python -V > /dev/null
> Python 3.3.2+
>
> 3.4$ ./python -V 2> /dev/null
> Python 3.4.0a1+
> 3.4$ ./python -V > /dev/null
>
> This might also explain why argparse uses stderr (other modules/scripts in
> the stdlib might do the same too).
>

Ah, right. On 3.4 Python's main.c uses printf for --version; on earlier
versions it's fprintf(stderr...)

I guess it's a no-brainer then; 3.4 has to be changed, but not earlier
versions. I'll whip up a quick patch.
msg196912 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-09-04 13:36
The Python executable change is from #18338
msg196916 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-09-04 13:49
Patch attached
msg196918 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-09-04 14:03
> This might also explain why argparse uses stderr (other modules/scripts in the stdlib might do the same too).

Lib/trace.py, Tools/pynche/Main.py, and Tools/i18n/pygettext.py write to the stdout.

Lib/smtpd.py and Tools/i18n/msgfmt.py write to the stderr.

The optparse module also writes to the stdout.
msg196919 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-09-04 14:13
You misplace Misc/NEWS entry in wrong section -- "What's New in Python 3.4.0 Alpha 1".

I think this change (as change of issue18338) worths the mentioning in Doc/whatsnew/3.4.rst.

Did you run all test suite? This change can affect other tests.
msg197068 - (view) Author: Roundup Robot (python-dev) Date: 2013-09-06 13:49
New changeset ec9a4b77f37b by Eli Bendersky in branch 'default':
Issue #18920: argparse's default version action (for -v, --version) should
http://hg.python.org/cpython/rev/ec9a4b77f37b
msg197069 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-09-06 13:50
Thanks, I moved the NEWS entry to the right place. Yes, all tests pass. I'll update whatsnew separately.
msg197072 - (view) Author: Roundup Robot (python-dev) Date: 2013-09-06 13:56
New changeset 587bdb940524 by Eli Bendersky in branch 'default':
Update whatsnew/3.4 wrt. --version going to stdout. #18338, #18920, #18922
http://hg.python.org/cpython/rev/587bdb940524
History
Date User Action Args
2013-09-06 13:57:07eli.benderskysetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: - Python 3.4
2013-09-06 13:56:39python-devsetmessages: + msg197072
2013-09-06 13:50:24eli.benderskysetmessages: + msg197069
2013-09-06 13:49:54python-devsetnosy: + python-dev
messages: + msg197068
2013-09-04 14:13:10serhiy.storchakasetmessages: + msg196919
2013-09-04 14:03:43serhiy.storchakasetmessages: + msg196918
2013-09-04 13:49:32eli.benderskysetfiles: + issue18920.1.patch
keywords: + patch
messages: + msg196916

stage: needs patch -> patch review
2013-09-04 13:36:11eli.benderskysetmessages: + msg196912
2013-09-04 13:34:23eli.benderskysetmessages: + msg196911
2013-09-04 13:26:47ezio.melottisetnosy: + ezio.melotti
messages: + msg196910

keywords: + easy
stage: needs patch
2013-09-04 13:17:59eli.benderskysetnosy: + eli.bendersky, serhiy.storchaka, bethard

messages: + msg196908
versions: + Python 3.4, - Python 3.2, Python 3.3
2013-09-04 12:30:47wolmacreate