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: optparse.OptionParser.get_usage uses wrong formatter
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: ccx, iritkatriel, sandro.tosi
Priority: normal Keywords: patch

Created on 2009-06-10 14:28 by ccx, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fix_optparse_usage_formatter.diff ccx, 2009-06-10 14:31 Proposed fix - correct indentation
fix_optparse_usage_formatter2.diff ccx, 2009-06-10 15:30 Alternative approach - more OO layered
Messages (7)
msg89202 - (view) Author: Jan Pobrislo (ccx) Date: 2009-06-10 14:28
When using OptionParser.format_help(formatter), the formatter parameter
should be used to format all of the help message. This is not the case
for usage message, as the method get_usage() is not passed the formatter
and always uses self.formatter. I'm using python-2.6.2-r1.
msg89204 - (view) Author: Jan Pobrislo (ccx) Date: 2009-06-10 15:07
On second thought method name starting with get_ doesn't signify any
formatting, so it might be better to either:

1) Move call to formatter.format_usage from get_usage directly to
format_help.

2) Create method format_usage in OptionParser and call it from there.
msg117747 - (view) Author: Sandro Tosi (sandro.tosi) * (Python committer) Date: 2010-09-30 15:57
Hello Jan,
I noticed this bug and I wondered: what's your opinion now?

Optparse is deprecated and it will be replaced by argparse, so I'm not sure it's "interesting" to introduce a new feature (the format_usage() method) but it might still be interesting to fix the previous behaviour.

So, are you still more inclined to add the new method or just correcting the harcoded formatter in get_usage() may be just fine?

If it's ok going on with the get_usage() fix, it's it just enough to:

    def get_usage(self, formatter=self.formatter):

and then just use 'formatter' (instead of checking if it's None, and then defaulting to self.formatter)? I didn't try this solution, so it might also be you've already tested and it's not working, just brain dumping :)

Regards,
Sandro
msg127771 - (view) Author: Sandro Tosi (sandro.tosi) * (Python committer) Date: 2011-02-02 22:16
Jan, are you still interested in this?
msg222379 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-05 23:48
Is it worth leaving this open as optparse was deprecated in 2.7 in favour of argparse?
msg380472 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-11-06 19:44
Jan, if you are still interested in fixing this you would need to add a test to the patch.
msg387020 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-02-15 16:04
optparse is deprecated an no longer in development, so unless someone objects I will close this issue.
History
Date User Action Args
2022-04-11 14:56:49adminsetgithub: 50502
2021-04-16 22:46:42iritkatrielsetstatus: pending -> closed
stage: resolved
2021-02-15 16:04:32iritkatrielsetstatus: open -> pending
resolution: wont fix
messages: + msg387020
2020-11-06 19:44:06iritkatrielsetnosy: + iritkatriel

messages: + msg380472
versions: + Python 3.8, Python 3.9, Python 3.10, - Python 2.6
2019-03-16 00:15:09BreamoreBoysetnosy: - BreamoreBoy
2014-07-05 23:48:47BreamoreBoysetnosy: + BreamoreBoy
messages: + msg222379
components: + Library (Lib), - Extension Modules
2011-02-02 22:16:42sandro.tosisetmessages: + msg127771
2010-09-30 15:57:02sandro.tosisetnosy: + sandro.tosi
messages: + msg117747
2009-06-10 15:30:39ccxsetfiles: + fix_optparse_usage_formatter2.diff
2009-06-10 15:30:30ccxsetfiles: - fix_optparse_usage_formatter2.diff
2009-06-10 15:07:35ccxsetfiles: + fix_optparse_usage_formatter2.diff

messages: + msg89204
2009-06-10 14:31:28ccxsetfiles: - fix_optparse_usage_formatter.diff
2009-06-10 14:31:03ccxsetfiles: + fix_optparse_usage_formatter.diff
2009-06-10 14:28:16ccxcreate