@@ -846,7 +846,7 @@ def format_usage(self):
846
846
return self .option_strings [0 ]
847
847
848
848
def __call__ (self , parser , namespace , values , option_string = None ):
849
- raise NotImplementedError (_ ( '.__call__() not defined' ) )
849
+ raise NotImplementedError ('.__call__() not defined' )
850
850
851
851
852
852
class BooleanOptionalAction (Action ):
@@ -1172,11 +1172,10 @@ def add_parser(self, name, *, deprecated=False, **kwargs):
1172
1172
aliases = kwargs .pop ('aliases' , ())
1173
1173
1174
1174
if name in self ._name_parser_map :
1175
- raise ArgumentError ( self , _ ( 'conflicting subparser: %s' ) % name )
1175
+ raise ValueError ( f 'conflicting subparser: { name } ' )
1176
1176
for alias in aliases :
1177
1177
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 } ' )
1180
1179
1181
1180
# create a pseudo-action to hold the choice help
1182
1181
if 'help' in kwargs :
@@ -1430,8 +1429,8 @@ def add_argument(self, *args, **kwargs):
1430
1429
chars = self .prefix_chars
1431
1430
if not args or len (args ) == 1 and args [0 ][0 ] not in chars :
1432
1431
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?' )
1435
1434
kwargs = self ._get_positional_kwargs (* args , ** kwargs )
1436
1435
1437
1436
# otherwise, we're adding an optional argument
@@ -1450,7 +1449,7 @@ def add_argument(self, *args, **kwargs):
1450
1449
action_name = kwargs .get ('action' )
1451
1450
action_class = self ._pop_action_class (kwargs )
1452
1451
if not callable (action_class ):
1453
- raise ValueError ('unknown action "%s"' % ( action_class ,) )
1452
+ raise ValueError ('unknown action { action_class!r}' )
1454
1453
action = action_class (** kwargs )
1455
1454
1456
1455
# raise an error if action for positional argument does not
@@ -1461,11 +1460,11 @@ def add_argument(self, *args, **kwargs):
1461
1460
# raise an error if the action type is not callable
1462
1461
type_func = self ._registry_get ('type' , action .type , action .type )
1463
1462
if not callable (type_func ):
1464
- raise ValueError ( '%r is not callable' % ( type_func ,) )
1463
+ raise TypeError ( f' { type_func !r } is not callable' )
1465
1464
1466
1465
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' )
1469
1468
1470
1469
# raise an error if the metavar does not match the type
1471
1470
if hasattr (self , "_get_formatter" ):
@@ -1518,8 +1517,8 @@ def _add_container_actions(self, container):
1518
1517
if group .title in title_group_map :
1519
1518
# This branch could happen if a derived class added
1520
1519
# 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 } '
9E81
code>
1521
+ raise ValueError (msg )
1523
1522
title_group_map [group .title ] = group
1524
1523
1525
1524
# map each action to its group
@@ -1560,7 +1559,7 @@ def _add_container_actions(self, container):
1560
1559
def _get_positional_kwargs (self , dest , ** kwargs ):
1561
1560
# make sure required is not specified
1562
1561
if 'required' in kwargs :
1563
- msg = _ ( "'required' is an invalid argument for positionals" )
1562
+ msg = "'required' is an invalid argument for positionals"
1564
1563
raise TypeError (msg )
1565
1564
1566
1565
# mark positional arguments as required if at least one is
@@ -1581,11 +1580,9 @@ def _get_optional_kwargs(self, *args, **kwargs):
1581
1580
for option_string in args :
1582
1581
# error on strings that don't start with an appropriate prefix
1583
1582
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} ' )
1589
1586
1590
1587
# strings starting with two prefix characters are long options
1591
1588
option_strings .append (option_string )
@@ -1601,8 +1598,8 @@ def _get_optional_kwargs(self, *args, **kwargs):
1601
1598
dest_option_string = option_strings [0 ]
1602
1599
dest = dest_option_string .lstrip (self .prefix_chars )
1603
1600
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 )
1606
1603
dest = dest .replace ('-' , '_' )
1607
1604
1608
1605
# return the updated keyword arguments
@@ -1618,8 +1615,8 @@ def _get_handler(self):
1618
1615
try :
1619
1616
return getattr (self , handler_func_name )
1620
1617
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 )
1623
1620
1624
1621
def _check_conflict (self , action ):
1625
1622
@@ -1727,7 +1724,7 @@ def __init__(self, container, required=False):
1727
1724
1728
1725
def _add_action (self , action ):
1729
1726
if action .required :
1730
- msg = _ ( 'mutually exclusive arguments must be optional' )
1727
+ msg = 'mutually exclusive arguments must be optional'
1731
1728
raise ValueError (msg )
1732
1729
action = self ._container ._add_action (action )
1733
1730
self ._group_actions .append (action )
@@ -1871,7 +1868,7 @@ def _get_kwargs(self):
1871
1868
# ==================================
1872
1869
def add_subparsers (self , ** kwargs ):
1873
1870
if self ._subparsers is not None :
1874
- raise ArgumentError ( None , _ ( 'cannot have multiple subparser arguments' ) )
1871
+ raise ValueError ( 'cannot have multiple subparser arguments' )
1875
1872
1876
1873
# add the parser class to the arguments if it's not present
1877
1874
kwargs .setdefault ('parser_class' , type (self ))
@@ -2565,8 +2562,7 @@ def _get_values(self, action, arg_strings):
2565
2562
def _get_value (self , action , arg_string ):
2566
2563
type_func = self ._registry_get ('type' , action .type , action .type )
2567
2564
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' )
2570
2566
2571
2567
# convert the value to the appropriate type
2572
2568
try :
0 commit comments