@@ -225,7 +225,8 @@ def format_help(self):
225225 # add the heading if the section was non-empty
226226 if self .heading is not SUPPRESS and self .heading is not None :
227227 current_indent = self .formatter ._current_indent
228- heading = '%*s%s:\n ' % (current_indent , '' , self .heading )
228+ heading_text = _ ('%(heading)s:' ) % dict (heading = self .heading )
229+ heading = '%*s%s\n ' % (current_indent , '' , heading_text )
229230 else :
230231 heading = ''
231232
@@ -415,6 +416,8 @@ def _format_actions_usage(self, actions, groups):
415416 suppressed_actions_count += 1
416417
417418 exposed_actions_count = group_action_count - suppressed_actions_count
419+ if not exposed_actions_count :
420+ continue
418421
419422 if not group .required :
420423 if start in inserts :
@@ -720,7 +723,7 @@ def _get_help_string(self, action):
720723 if action .default is not SUPPRESS :
721724 defaulting_nargs = [OPTIONAL , ZERO_OR_MORE ]
722725 if action .option_strings or action .nargs in defaulting_nargs :
723- help += ' (default: %(default)s)'
726+ help += _ ( ' (default: %(default)s)' )
724727 return help
725728
726729
@@ -1149,7 +1152,9 @@ def __init__(self,
11491152 version = None ,
11501153 dest = SUPPRESS ,
11511154 default = SUPPRESS ,
1152- help = "show program's version number and exit" ):
1155+ help = None ):
1156+ if help is None :
1157+ help = _ ("show program's version number and exit" )
11531158 super (_VersionAction , self ).__init__ (
11541159 option_strings = option_strings ,
11551160 dest = dest ,
@@ -2004,7 +2009,7 @@ def consume_optional(start_index):
20042009
20052010 # get the optional identified at this index
20062011 option_tuple = option_string_indices [start_index ]
2007- action , option_string , explicit_arg = option_tuple
2012+ action , option_string , sep , explicit_arg = option_tuple
20082013
20092014 # identify additional optionals in the same arg string
20102015 # (e.g. -xyz is the same as -x -y -z if no args are required)
@@ -2031,18 +2036,27 @@ def consume_optional(start_index):
20312036 and option_string [1 ] not in chars
20322037 and explicit_arg != ''
20332038 ):
2039+ if sep or explicit_arg [0 ] in chars :
2040+ msg = _ ('ignored explicit argument %r' )
2041+ raise ArgumentError (action , msg % explicit_arg )
20342042 action_tuples .append ((action , [], option_string ))
20352043 char = option_string [0 ]
20362044 option_string = char + explicit_arg [0 ]
2037- new_explicit_arg = explicit_arg [1 :] or None
20382045 optionals_map = self ._option_string_actions
20392046 if option_string in optionals_map :
20402047 action = optionals_map [option_string ]
2041- explicit_arg = new_explicit_arg
2048+ explicit_arg = explicit_arg [1 :]
2049+ if not explicit_arg :
2050+ sep = explicit_arg = None
2051+ elif explicit_arg [0 ] == '=' :
2052+ sep = '='
2053+ explicit_arg = explicit_arg [1 :]
2054+ else :
2055+ sep = ''
20422056 else :
2043- msg = _ ( 'ignored explicit argument %r' )
2044- raise ArgumentError ( action , msg % explicit_arg )
2045-
2057+ extras . append ( char + explicit_arg )
2058+ stop = start_index + 1
2059+ break
20462060 # if the action expect exactly one argument, we've
20472061 # successfully matched the option; exit the loop
20482062 elif arg_count == 1 :
@@ -2262,18 +2276,17 @@ def _parse_optional(self, arg_string):
22622276 # if the option string is present in the parser, return the action
22632277 if arg_string in self ._option_string_actions :
22642278 action = self ._option_string_actions [arg_string ]
2265- return action , arg_string , None
2279+ return action , arg_string , None , None
22662280
22672281 # if it's just a single character, it was meant to be positional
22682282 if len (arg_string ) == 1 :
22692283 return None
22702284
22712285 # if the option string before the "=" is present, return the action
2272- if '=' in arg_string :
2273- option_string , explicit_arg = arg_string .split ('=' , 1 )
2274- if option_string in self ._option_string_actions :
2275- action = self ._option_string_actions [option_string ]
2276- return action , option_string , explicit_arg
2286+ option_string , sep , explicit_arg = arg_string .partition ('=' )
2287+ if sep and option_string in self ._option_string_actions :
2288+ action = self ._option_string_actions [option_string ]
2289+ return action , option_string , sep , explicit_arg
22772290
22782291 # search through all possible prefixes of the option string
22792292 # and all actions in the parser for possible interpretations
@@ -2282,7 +2295,7 @@ def _parse_optional(self, arg_string):
22822295 # if multiple actions match, the option string was ambiguous
22832296 if len (option_tuples ) > 1 :
22842297 options = ', ' .join ([option_string
2285- for action , option_string , explicit_arg in option_tuples ])
2298+ for action , option_string , sep , explicit_arg in option_tuples ])
22862299 args = {'option' : arg_string , 'matches' : options }
22872300 msg = _ ('ambiguous option: %(option)s could match %(matches)s' )
22882301 self .error (msg % args )
@@ -2306,7 +2319,7 @@ def _parse_optional(self, arg_string):
23062319
23072320 # it was meant to be an optional but there is no such option
23082321 # in this parser (though it might be a valid option in a subparser)
2309- return None , arg_string , None
2322+ return None , arg_string , None , None
23102323
23112324 def _get_option_tuples (self , option_string ):
23122325 result = []
@@ -2316,34 +2329,31 @@ def _get_option_tuples(self, option_string):
23162329 chars = self .prefix_chars
23172330 if option_string [0 ] in chars and option_string [1 ] in chars :
23182331 if self .allow_abbrev :
2319- if '=' in option_string :
2320- option_prefix , explicit_arg = option_string .split ('=' , 1 )
2321- else :
2322- option_prefix = option_string
2323- explicit_arg = None
2332+ option_prefix , sep , explicit_arg = option_string .partition ('=' )
2333+ if not sep :
2334+ sep = explicit_arg = None
23242335 for option_string in self ._option_string_actions :
23252336 if option_string .startswith (option_prefix ):
23262337 action = self ._option_string_actions [option_string ]
2327- tup = action , option_string , explicit_arg
2338+ tup = action , option_string , sep , explicit_arg
23282339 result .append (tup )
23292340
23302341 # single character options can be concatenated with their arguments
23312342 # but multiple character options always have to have their argument
23322343 # separate
23332344 elif option_string [0 ] in chars and option_string [1 ] not in chars :
23342345 option_prefix = option_string
2335- explicit_arg = None
23362346 short_option_prefix = option_string [:2 ]
23372347 short_explicit_arg = option_string [2 :]
23382348
23392349 for option_string in self ._option_string_actions :
23402350 if option_string == short_option_prefix :
23412351 action = self ._option_string_actions [option_string ]
2342- tup = action , option_string , short_explicit_arg
2352+ tup = action , option_string , '' , short_explicit_arg
23432353 result .append (tup )
23442354 elif option_string .startswith (option_prefix ):
23452355 action = self ._option_string_actions [option_string ]
2346- tup = action , option_string , explicit_arg
2356+ tup = action , option_string , None , None
23472357 result .append (tup )
23482358
23492359 # shouldn't ever get here
0 commit comments