You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
argparse version action should print to stdout, not stderr #63120
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2013-09-06.13:57:07.095>created_at=<Date2013-09-04.12:30:47.440>labels= ['easy', 'type-bug']
title='argparse version action should print to stdout, not stderr'updated_at=<Date2018-03-24.16:17:16.912>user='https://github.com/wm75'
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
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?
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+
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+
changed the title [-]argparse module version action[/-][+]argparse version action should print to stdout, not stderr[/+]on Jul 4, 2016
StefanSauer commented on Mar 24, 2018
StefanSauermannequin
Mannequin
More actions
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"; forpin $list; do \
case' 'in \
*" $p "*|*" ../../$p "*) continue;; \
esac; \
f=`echo "$p" | sed 's,^.*/,,;s,x,x,'`; \
foroptin--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 :; \
elseecho"$f does not support $opt"1>&2; bad=1; fi; \
done; \
done; rm-fc${pid}_.???; exit $badgtkdoc-checkdoesnotsupport--versiongtkdoc-fixxrefdoesnotsupport--versiongtkdoc-mkdbdoesnotsupport--versiongtkdoc-mkhtmldoesnotsupport--versiongtkdoc-mkhtml2doesnotsupport--versiongtkdoc-mkmandoesnotsupport--versiongtkdoc-mkpdfdoesnotsupport--versiongtkdoc-rebasedoesnotsupport--versiongtkdoc-scandoesnotsupport--versiongtkdoc-scangobjdoesnotsupport--versionMakefile:637: recipefortarget'installcheck-binSCRIPTS'failed
Activity
wm75 commentedon Sep 4, 2013
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
elibendersky commentedon Sep 4, 2013
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?
ezio-melotti commentedon Sep 4, 2013
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).
elibendersky commentedon Sep 4, 2013
On Wed, Sep 4, 2013 at 6:26 AM, Ezio Melotti <report@bugs.python.org> wrote:
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.
elibendersky commentedon Sep 4, 2013
The Python executable change is from bpo-18338
elibendersky commentedon Sep 4, 2013
Patch attached
serhiy-storchaka commentedon Sep 4, 2013
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.
serhiy-storchaka commentedon Sep 4, 2013
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 bpo-18338) worths the mentioning in Doc/whatsnew/3.4.rst.
Did you run all test suite? This change can affect other tests.
python-dev commentedon Sep 6, 2013
New changeset ec9a4b77f37b by Eli Bendersky in branch 'default':
Issue bpo-18920: argparse's default version action (for -v, --version) should
http://hg.python.org/cpython/rev/ec9a4b77f37b
elibendersky commentedon Sep 6, 2013
Thanks, I moved the NEWS entry to the right place. Yes, all tests pass. I'll update whatsnew separately.
python-dev commentedon Sep 6, 2013
New changeset 587bdb940524 by Eli Bendersky in branch 'default':
Update whatsnew/3.4 wrt. --version going to stdout. bpo-18338, bpo-18920, bpo-18922
http://hg.python.org/cpython/rev/587bdb940524
[-]argparse module version action[/-][+]argparse version action should print to stdout, not stderr[/+]StefanSauer commentedon Mar 24, 2018
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:
serhiy-storchaka commentedon Mar 24, 2018
You can implement your own version action which outputs to stdout and use it for -V and --version.