@@ -52,7 +52,7 @@ def signature(obj):
52
52
'''Get a signature object for the passed callable.'''
53
53
54
54
if not callable (obj ):
55
- raise TypeError ('{0 !r} is not a callable object' .format (obj ))
55
+ raise TypeError ('{!r} is not a callable object' .format (obj ))
56
56
57
57
if isinstance (obj , types .MethodType ):
58
58
sig = signature (obj .__func__ )
@@ -99,7 +99,7 @@ def signature(obj):
99
99
try :
100
100
ba = sig .bind_partial (* partial_args , ** partial_keywords )
101
101
except TypeError as ex :
102
- msg = 'partial object {0 !r} has incorrect arguments' .format (obj )
102
+ msg = 'partial object {!r} has incorrect arguments' .format (obj )
103
103
raise ValueError (msg )
104
104
105
105
for arg_name , arg_value in ba .arguments .items ():
@@ -166,10 +166,10 @@ def signature(obj):
166
166
167
167
if isinstance (obj , types .BuiltinFunctionType ):
168
168
# Raise a nicer error message for builtins
169
- msg = 'no signature found for builtin function {0 !r}' .format (obj )
169
+ msg = 'no signature found for builtin function {!r}' .format (obj )
170
170
raise ValueError (msg )
171
171
172
- raise ValueError ('callable {0 !r} is not supported by signature' .format (obj ))
172
+ raise ValueError ('callable {!r} is not supported by signature' .format (obj ))
173
173
174
174
175
175
class _void (object ):
@@ -190,7 +190,7 @@ def __str__(self):
190
190
return self ._name
191
191
192
192
def __repr__ (self ):
193
- return '<_ParameterKind: {0 !r}>' .format (self ._name )
193
+ return '<_ParameterKind: {!r}>' .format (self ._name )
194
194
195
195
196
196
_POSITIONAL_ONLY = _ParameterKind (0 , name = 'POSITIONAL_ONLY' )
@@ -238,7 +238,7 @@ def __init__(self, name, kind, default=_empty, annotation=_empty,
238
238
239
239
if default is not _empty :
240
240
if kind in (_VAR_POSITIONAL , _VAR_KEYWORD ):
241
- msg = '{0 } parameters cannot have default values' .format (kind )
241
+ msg = '{} parameters cannot have default values' .format (kind )
242
242
raise ValueError (msg )
243
243
self ._default = default
244
244
self ._annotation = annotation
@@ -251,7 +251,7 @@ def __init__(self, name, kind, default=_empty, annotation=_empty,
251
251
else :
252
252
name = str (name )
253
253
if kind != _POSITIONAL_ONLY and not re .match (r'[a-z_]\w*$' , name , re .I ):
254
- msg = '{0 !r} is not a valid parameter name' .format (name )
254
+ msg = '{!r} is not a valid parameter name' .format (name )
255
255
raise ValueError (msg )
256
256
self ._name = name
257
257
@@ -302,15 +302,15 @@ def __str__(self):
302
302
if kind == _POSITIONAL_ONLY :
303
303
if formatted is None :
304
304
formatted = ''
305
- formatted = '<{0 }>' .format (formatted )
305
+ formatted = '<{}>' .format (formatted )
306
306
307
307
# Add annotation and default value
308
308
if self ._annotation is not _empty :
309
- formatted = '{0 }:{1 }' .format (formatted ,
309
+ formatted = '{}:{}' .format (formatted ,
310
310
formatannotation (self ._annotation ))
311
311
312
312
if self ._default is not _empty :
313
- formatted = '{0 }={1 }' .format (formatted , repr (self ._default ))
313
+ formatted = '{}={}' .format (formatted , repr (self ._default ))
314
314
315
315
if kind == _VAR_POSITIONAL :
316
316
formatted = '*' + formatted
@@ -320,11 +320,11 @@ def __str__(self):
320
320
return formatted
321
321
322
322
def __repr__ (self ):
323
- return '<{0 } at {1 :#x} {2 !r}>' .format (self .__class__ .__name__ ,
323
+ return '<{} at {:#x} {!r}>' .format (self .__class__ .__name__ ,
324
324
id (self ), self .name )
325
325
326
326
def __hash__ (self ):
327
- msg = "unhashable type: '{0 }'" .format (self .__class__ .__name__ )
327
+ msg = "unhashable type: '{}'" .format (self .__class__ .__name__ )
328
328
raise TypeError (msg )
329
329
330
330
def __eq__ (self , other ):
@@ -421,7 +421,7 @@ def kwargs(self):
421
421
return kwargs
422
422
423
423
def __hash__ (self ):
424
- msg = "unhashable type: '{0 }'" .format (self .__class__ .__name__ )
424
+ msg = "unhashable type: '{}'" .format (self .__class__ .__name__ )
425
425
raise TypeError (msg )
426
426
427
427
def __eq__ (self , other ):
@@ -489,7 +489,7 @@ def __init__(self, parameters=None, return_annotation=_empty,
489
489
param = param .replace (name = name )
490
490
491
491
if name in params :
492
- msg = 'duplicate parameter name: {0 !r}' .format (name )
492
+ msg = 'duplicate parameter name: {!r}' .format (name )
493
493
raise ValueError (msg )
494
494
params [name ] = param
495
495
else :
@@ -504,7 +504,7 @@ def from_function(cls, func):
504
504
'''Constructs Signature for the given python function'''
505
505
506
506
if not isinstance (func , types .FunctionType ):
507
- raise TypeError ('{0 !r} is not a Python function' .format (func ))
507
+ raise TypeError ('{!r} is not a Python function' .format (func ))
508
508
509
509
Parameter = cls ._parameter_cls
510
510
@@ -599,7 +599,7 @@ def replace(self, parameters=_void, return_annotation=_void):
599
599
return_annotation = return_annotation )
600
600
601
601
def __hash__ (self ):
602
- msg = "unhashable type: '{0 }'" .format (self .__class__ .__name__ )
602
+ msg = "unhashable type: '{}'" .format (self .__class__ .__name__ )
603
603
raise TypeError (msg )
604
604
605
605
def __eq__ (self , other ):
@@ -608,8 +608,8 @@ def __eq__(self, other):
608
608
len (self .parameters ) != len (other .parameters )):
609
609
return False
610
610
611
- other_positions = dict (( param , idx )
612
- for idx , param in enumerate (other .parameters .keys ()))
611
+ other_positions = { param : idx
612
+ for idx , param in enumerate (other .parameters .keys ())}
613
613
614
614
for idx , (param_name , param ) in enumerate (self .parameters .items ()):
615
615
if param .kind == _KEYWORD_ONLY :
@@ -799,10 +799,10 @@ def __str__(self):
799
799
800
800
result .append (formatted )
801
801
802
- rendered = '({0 })' .format (', ' .join (result ))
802
+ rendered = '({})' .format (', ' .join (result ))
803
803
804
804
if self .return_annotation is not _empty :
805
805
anno = formatannotation (self .return_annotation )
806
- rendered += ' -> {0 }' .format (anno )
806
+ rendered += ' -> {}' .format (anno )
807
807
808
808
return rendered
0 commit comments