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.

Author will
Recipients paul.j3, rhettinger, will
Date 2021-01-21.22:15:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1611267358.81.0.541537290704.issue42980@roundup.psfhosted.org>
In-reply-to
Content
The main contribution of my PR is simply factoring out _format_option_with_args as an overridable method. Note that this actually enables subclassing HelpFormatter to produce all the examples you presented above with 1-3 trivial lines of code, as opposed to overriding the entire _format_action_invocation which is 20 lines in the base class.

If HelpFormatter had a stable internal structure (i.e. some sort of assurance that it's overridable methods were not subject to change), I wouldn't have bothered including an implementation of GnuStyleLongOptionsHelpFormatter in this PR, since I could just implement it downstream as-needed. However, I chose to push it upstream because a) it's trivial and non-invasive and b) it establishes a use-case of _format_option_with_args for posterity, just in case anybody came in later and saw such a trivial, "private" (underscore-prefixed) method and decided to inline it.

This lack of perceived stability is alluded to in https://bugs.python.org/issue42966. My preferred solution would be to refactor HelpFormatter to have more overridable methods like this, make them non-"private", document them properly, and keep them relatively stable. In order to do that, we'd want to establish all the desired use-cases and be sure to craft the method structure in such a way that they're all supported. Since that would be a somewhat daunting design task and probably not high on the priority list atm, I think this small incremental improvement pushes things in the right direction; establishing a desirable use-case without committing to too many implementation details yet.
History
Date User Action Args
2021-01-21 22:15:58willsetrecipients: + will, rhettinger, paul.j3
2021-01-21 22:15:58willsetmessageid: <1611267358.81.0.541537290704.issue42980@roundup.psfhosted.org>
2021-01-21 22:15:58willlinkissue42980 messages
2021-01-21 22:15:58willcreate