classification
Title: argparse should use the new Formatter class
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: bethard, flox, paul.j3, petri.lehtinen, poke, rhettinger
Priority: low Keywords:

Created on 2011-10-27 20:19 by poke, last changed 2018-09-30 06:50 by paul.j3. This issue is now closed.

Messages (4)
msg146516 - (view) Author: Patrick Westerhoff (poke) Date: 2011-10-27 20:19
Hey,

according to PEP 3101, the new string.Formatter class is supposed to replace the old string formatting with %. At least that is what I was always thinking. Given that argparse is a Python 3.2+ exclusive module, I think it should make use of that new formatting method.

Is there any special reason why that is not the case and the old %-formatting is used? It feels a bit weird to have Python 3 code using only string.Formatter and then have a short section where the old formatter is used – especially when that module was introduced with Python 3.2.
msg146520 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2011-10-27 21:42
Well argparse exists since 2006 (ref [1]), and "should work on Python >= 2.3" (ref [2]).
It was merged in the standard library with Python 3.2.

However, I agree we may switch to the advanced string formatting for this module.


[1] http://objectmix.com/python/180879-%5Bann%5D-argparse-module.html
[2] http://pypi.python.org/pypi/argparse#compatibility
msg146533 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-10-28 03:14
There's no reason to switch the implementation.  The % formatting isn't going away and we've decided against doing switch-overs in existing code (it risks introducing bugs while conferring zero benefits to users).
msg326708 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2018-09-30 06:50
Thinking about https://bugs.python.org/issue34744, I realized that the new style formatting could provide some added flexibility to the help lines.

I think new style formatting could be added in parallel with the existing style, as an alternative, not as a replacement.

With that option a help line like:

'help for {dest} or {option_strings[0]} default is {default}'  

could be used.
History
Date User Action Args
2018-09-30 06:50:24paul.j3setmessages: + msg326708
2013-08-09 06:00:08paul.j3setnosy: + paul.j3
2011-10-29 19:45:55rhettingersetstatus: open -> closed
resolution: not a bug
2011-10-28 05:32:05petri.lehtinensetnosy: + petri.lehtinen
2011-10-28 03:14:34rhettingersetnosy: + rhettinger
messages: + msg146533
2011-10-27 21:57:11floxsetnosy: + bethard
2011-10-27 21:42:55floxsetpriority: normal -> low
versions: - Python 3.2, Python 3.4
nosy: + flox

messages: + msg146520
2011-10-27 20:19:11pokecreate