This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2013-09-04 12:30 by wolma, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue18920.1.patch eli.bendersky, 2013-09-04 13:49
Messages (13)
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) (Python triager) 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) (Python triager) 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
msg314373 - (view) Author: Stefan Sauer (Stefan Sauer) Date: 2018-03-24 15:04
Is there a workaround for python2? The issue is that autotools is checking that installed tools support --help and --version and it expects those to stdout:

bad=0; pid=$$; list="gtkdoc-check gtkdoc-depscan gtkdoc-fixxref gtkdoc-mkdb gtkdoc-mkhtml gtkdoc-mkhtml2 gtkdoc-mkman gtkdoc-mkpdf gtkdoc-rebase gtkdoc-scan gtkdoc-scangobj gtkdocize"; for p in $list; do \
  case '  ' in \
   *" $p "* | *" ../../$p "*) continue;; \
  esac; \
  f=`echo "$p" | sed 's,^.*/,,;s,x,x,'`; \
  for opt in --help --version; do \
    if "/home/ensonic/projects/gnome/gtk-doc/gtk-doc-1.27.1/_inst/bin/$f" $opt >c${pid}_.out \
         2>c${pid}_.err </dev/null \
         && test -n "`cat c${pid}_.out`" \
         && test -z "`cat c${pid}_.err`"; then :; \
    else echo "$f does not support $opt" 1>&2; bad=1; fi; \
  done; \
done; rm -f c${pid}_.???; exit $bad
gtkdoc-check does not support --version
gtkdoc-fixxref does not support --version
gtkdoc-mkdb does not support --version
gtkdoc-mkhtml does not support --version
gtkdoc-mkhtml2 does not support --version
gtkdoc-mkman does not support --version
gtkdoc-mkpdf does not support --version
gtkdoc-rebase does not support --version
gtkdoc-scan does not support --version
gtkdoc-scangobj does not support --version
Makefile:637: recipe for target 'installcheck-binSCRIPTS' failed
msg314374 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-03-24 16:17
You can implement your own version action which outputs to stdout and use it for -V and --version.
History
Date User Action Args
2022-04-11 14:57:50adminsetgithub: 63120
2018-03-24 16:17:16serhiy.storchakasetmessages: + msg314374
2018-03-24 15:04:25Stefan Sauersetnosy: + Stefan Sauer
messages: + msg314373
2016-07-04 16:48:49jwilksetnosy: + jwilk

title: argparse module version action -> argparse version action should print to stdout, not stderr
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