@@ -846,7 +846,7 @@ def format_usage(self):
846846 return self .option_strings [0 ]
847847
848848 def __call__ (self , parser , namespace , values , option_string = None ):
849- raise NotImplementedError (_ ( '.__call__() not defined' ) )
849+ raise NotImplementedError ('.__call__() not defined' )
850850
851851
852852class BooleanOptionalAction (Action ):
@@ -1172,11 +1172,10 @@ def add_parser(self, name, *, deprecated=False, **kwargs):
11721172 aliases = kwargs .pop ('aliases' , ())
11731173
11741174 if name in self ._name_parser_map :
1175- raise ArgumentError ( self , _ ( 'conflicting subparser: %s' ) % name )
1175+ raise ValueError ( f 'conflicting subparser: { name } ' )
11761176 for alias in aliases :
11771177 if alias in self ._name_parser_map :
1178- raise ArgumentError (
1179- self , _ ('conflicting subparser alias: %s' ) % alias )
1178+ raise ValueError (f'conflicting subparser alias: { alias } ' )
11801179
11811180 # create a pseudo-action to hold the choice help
11821181 if 'help' in kwargs :
@@ -1430,8 +1429,8 @@ def add_argument(self, *args, **kwargs):
14301429 chars = self .prefix_chars
14311430 if not args or len (args ) == 1 and args [0 ][0 ] not in chars :
14321431 if args and 'dest' in kwargs :
1433- raise ValueError ('dest supplied twice for positional argument,'
1434- ' did you mean metavar?' )
1432+ raise TypeError ('dest supplied twice for positional argument,'
1433+ ' did you mean metavar?' )
14351434 kwargs = self ._get_positional_kwargs (* args , ** kwargs )
14361435
14371436 # otherwise, we're adding an optional argument
@@ -1450,7 +1449,7 @@ def add_argument(self, *args, **kwargs):
14501449 action_name = kwargs .get ('action' )
14511450 action_class = self ._pop_action_class (kwargs )
14521451 if not callable (action_class ):
1453- raise ValueError ('unknown action "%s"' % ( action_class ,) )
1452+ raise ValueError ('unknown action { action_class!r}' )
14541453 action = action_class (** kwargs )
14551454
14561455 # raise an error if action for positional argument does not
@@ -1461,11 +1460,11 @@ def add_argument(self, *args, **kwargs):
14611460 # raise an error if the action type is not callable
14621461 type_func = self ._registry_get ('type' , action .type , action .type )
14631462 if not callable (type_func ):
1464- raise ValueError ( '%r is not callable' % ( type_func ,) )
1463+ raise TypeError ( f' { type_func !r } is not callable' )
14651464
14661465 if type_func is FileType :
1467- raise ValueError ( '%r is a FileType class object, instance of it '
1468- ' must be passed' % ( type_func ,) )
1466+ raise TypeError ( f' { type_func !r } is a FileType class object, '
1467+ f'instance of it must be passed' )
14691468
14701469 # raise an error if the metavar does not match the type
14711470 if hasattr (self , "_get_formatter" ):
@@ -1518,8 +1517,8 @@ def _add_container_actions(self, container):
15181517 if group .title in title_group_map :
15191518 # This branch could happen if a derived class added
15201519 # groups with duplicated titles in __init__
1521- msg = _ ( 'cannot merge actions - two groups are named %r' )
1522- raise ValueError (msg % ( group . title ) )
1520+ msg = f 'cannot merge actions - two groups are named { group . title !r } '
1521+ raise ValueError (msg )
15231522 title_group_map [group .title ] = group
15241523
15251524 # map each action to its group
@@ -1560,7 +1559,7 @@ def _add_container_actions(self, container):
15601559 def _get_positional_kwargs (self , dest , ** kwargs ):
15611560 # make sure required is not specified
15621561 if 'required' in kwargs :
1563- msg = _ ( "'required' is an invalid argument for positionals" )
1562+ msg = "'required' is an invalid argument for positionals"
15641563 raise TypeError (msg )
15651564
15661565 # mark positional arguments as required if at least one is
@@ -1581,11 +1580,9 @@ def _get_optional_kwargs(self, *args, **kwargs):
15811580 for option_string in args :
15821581 # error on strings that don't start with an appropriate prefix
15831582 if not option_string [0 ] in self .prefix_chars :
1584- args = {'option' : option_string ,
1585- 'prefix_chars' : self .prefix_chars }
1586- msg = _ ('invalid option string %(option)r: '
1587- 'must start with a character %(prefix_chars)r' )
1588- raise ValueError (msg % args )
1583+ raise ValueError (
1584+ f'invalid option string { option_string !r} : '
1585+ f'must start with a character { self .prefix_chars !r} ' )
15891586
15901587 # strings starting with two prefix characters are long options
15911588 option_strings .append (option_string )
@@ -1601,8 +1598,8 @@ def _get_optional_kwargs(self, *args, **kwargs):
16011598 dest_option_string = option_strings [0 ]
16021599 dest = dest_option_string .lstrip (self .prefix_chars )
16031600 if not dest :
1604- msg = _ ( 'dest= is required for options like %r' )
1605- raise ValueError (msg % option_string )
1601+ msg = f 'dest= is required for options like { option_string !r } '
1602+ raise TypeError (msg )
16061603 dest = dest .replace ('-' , '_' )
16071604
16081605 # return the updated keyword arguments
@@ -1618,8 +1615,8 @@ def _get_handler(self):
16181615 try :
16191616 return getattr (self , handler_func_name )
16201617 except AttributeError :
1621- msg = _ ( 'invalid conflict_resolution value: %r' )
1622- raise ValueError (msg % self . conflict_handler )
1618+ msg = f 'invalid conflict_resolution value: { self . conflict_handler !r } '
1619+ raise ValueError (msg )
16231620
16241621 def _check_conflict (self , action ):
16251622
@@ -1727,7 +1724,7 @@ def __init__(self, container, required=False):
17271724
17281725 def _add_action (self , action ):
17291726 if action .required :
1730- msg = _ ( 'mutually exclusive arguments must be optional' )
1727+ msg = 'mutually exclusive arguments must be optional'
17311728 raise ValueError (msg )
17321729 action = self ._container ._add_action (action )
17331730 self ._group_actions .append (action )
@@ -1871,7 +1868,7 @@ def _get_kwargs(self):
18711868 # ==================================
18721869 def add_subparsers (self , ** kwargs ):
18731870 if self ._subparsers is not None :
1874- raise ArgumentError ( None , _ ( 'cannot have multiple subparser arguments' ) )
1871+ raise ValueError ( 'cannot have multiple subparser arguments' )
18751872
18761873 # add the parser class to the arguments if it's not present
18771874 kwargs .setdefault ('parser_class' , type (self ))
@@ -2565,8 +2562,7 @@ def _get_values(self, action, arg_strings):
25652562 def _get_value (self , action , arg_string ):
25662563 type_func = self ._registry_get ('type' , action .type , action .type )
25672564 if not callable (type_func ):
2568- msg = _ ('%r is not callable' )
2569- raise ArgumentError (action , msg % type_func )
2565+ raise TypeError (f'{ type_func !r} is not callable' )
25702566
25712567 # convert the value to the appropriate type
25722568 try :
0 commit comments