File tree 2 files changed +26
-4
lines changed
2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -2723,15 +2723,13 @@ def format_help(self):
2723
2723
return formatter .format_help ()
2724
2724
2725
2725
def _get_formatter (self ):
2726
- if isinstance (self .formatter_class , type ) and issubclass (
2727
- self .formatter_class , HelpFormatter
2728
- ):
2726
+ try :
2729
2727
return self .formatter_class (
2730
2728
prog = self .prog ,
2731
2729
prefix_chars = self .prefix_chars ,
2732
2730
color = self .color ,
2733
2731
)
2734
- else :
2732
+ except TypeError :
2735
2733
return self .formatter_class (prog = self .prog )
2736
2734
2737
2735
# =====================
Original file line number Diff line number Diff line change @@ -5176,6 +5176,30 @@ class TestHelpTupleMetavarPositional(HelpTestCase):
5176
5176
version = ''
5177
5177
5178
5178
5179
+ class TestHelpFormatter (HelpTestCase ):
5180
+ """Test the HelpFormatter"""
5181
+
5182
+ # Test subclassing the help formatter
5183
+ class MyFormatter (argparse .HelpFormatter ):
5184
+ def __init__ (self , prog ) -> None :
5185
+ super ().__init__ (prog )
5186
+
5187
+ parser_signature = Sig (
5188
+ prog = "PROG" ,
5189
+ formatter_class = MyFormatter ,
5190
+ description = "Test with subclassing the help formatter" ,
5191
+ )
5192
+ usage = '''\
5193
+ usage: PROG [-h]
5194
+ '''
5195
+ help = usage + '''\
5196
+
5197
+ Test with subclassing the help formatter
5198
+
5199
+ options:
5200
+ -h, --help show this help message and exit
5201
+ '''
5202
+
5179
5203
class TestHelpRawText (HelpTestCase ):
5180
5204
"""Test the RawTextHelpFormatter"""
5181
5205
You can’t perform that action at this time.
0 commit comments