File tree Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -2723,15 +2723,13 @@ def format_help(self):
27232723 return formatter .format_help ()
27242724
27252725 def _get_formatter (self ):
2726- if isinstance (self .formatter_class , type ) and issubclass (
2727- self .formatter_class , HelpFormatter
2728- ):
2726+ try :
27292727 return self .formatter_class (
27302728 prog = self .prog ,
27312729 prefix_chars = self .prefix_chars ,
27322730 color = self .color ,
27332731 )
2734- else :
2732+ except TypeError :
27352733 return self .formatter_class (prog = self .prog )
27362734
27372735 # =====================
Original file line number Diff line number Diff line change @@ -5176,6 +5176,30 @@ class TestHelpTupleMetavarPositional(HelpTestCase):
51765176 version = ''
51775177
51785178
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+
51795203class TestHelpRawText (HelpTestCase ):
51805204 """Test the RawTextHelpFormatter"""
51815205
Original file line number Diff line number Diff line change 1+ Fix subclassing :meth: `argparse.HelpFormatter `. Patch by Hugo van Kemenade.
You can’t perform that action at this time.
0 commit comments