@@ -54,7 +54,7 @@ def signature(obj):
5454 """Get a signature object for the passed callable."""
5555
5656 if not callable (obj ):
57- raise TypeError ("{ !r} is not a callable object". format ( obj ) )
57+ raise TypeError (f" { obj !r} is not a callable object" )
5858
5959 if isinstance (obj , types .MethodType ):
6060 sig = signature (obj .__func__ )
@@ -101,7 +101,7 @@ def signature(obj):
101101 try :
102102 ba = sig .bind_partial (* partial_args , ** partial_keywords )
103103 except TypeError as ex :
104- msg = "partial object {!r} has incorrect arguments" . format ( obj )
104+ msg = f "partial object { obj !r} has incorrect arguments"
105105 raise ValueError (msg )
106106
107107 for arg_name , arg_value in ba .arguments .items ():
@@ -171,10 +171,10 @@ def signature(obj):
171171
172172 if isinstance (obj , types .BuiltinFunctionType ):
173173 # Raise a nicer error message for builtins
174- msg = "no signature found for builtin function {!r}" . format ( obj )
174+ msg = f "no signature found for builtin function { obj !r} "
175175 raise ValueError (msg )
176176
177- raise ValueError ("callable {!r} is not supported by signature" . format ( obj ) )
177+ raise ValueError (f "callable { obj !r} is not supported by signature" )
178178
179179
180180class _void (object ):
@@ -195,7 +195,7 @@ def __str__(self):
195195 return self ._name
196196
197197 def __repr__ (self ):
198- return "<_ParameterKind: {!r}>" . format ( self . _name )
198+ return f "<_ParameterKind: { self . _name !r} >"
199199
200200
201201_POSITIONAL_ONLY = _ParameterKind (0 , name = "POSITIONAL_ONLY" )
@@ -249,7 +249,7 @@ def __init__(
249249
250250 if default is not _empty :
251251 if kind in (_VAR_POSITIONAL , _VAR_KEYWORD ):
252- msg = "{ } parameters cannot have default values". format ( kind )
252+ msg = f" { kind } parameters cannot have default values"
253253 raise ValueError (msg )
254254 self ._default = default
255255 self ._annotation = annotation
@@ -263,7 +263,7 @@ def __init__(
263263 else :
264264 name = str (name )
265265 if kind != _POSITIONAL_ONLY and not re .match (r"[a-z_]\w*$" , name , re .I ):
266- msg = "{ !r} is not a valid parameter name". format ( name )
266+ msg = f" { name !r} is not a valid parameter name"
267267 raise ValueError (msg )
268268 self ._name = name
269269
@@ -325,14 +325,14 @@ def __str__(self):
325325 if kind == _POSITIONAL_ONLY :
326326 if formatted is None :
327327 formatted = ""
328- formatted = "<{}>" . format ( formatted )
328+ formatted = f "<{ formatted } >"
329329
330330 # Add annotation and default value
331331 if self ._annotation is not _empty :
332- formatted = "{ }:{}" . format ( formatted , formatannotation (self ._annotation ))
332+ formatted = f" { formatted } :{ formatannotation (self ._annotation )} "
333333
334334 if self ._default is not _empty :
335- formatted = "{ }={}" . format ( formatted , repr (self ._default ))
335+ formatted = f" { formatted } ={ repr (self ._default )} "
336336
337337 if kind == _VAR_POSITIONAL :
338338 formatted = "*" + formatted
@@ -342,10 +342,10 @@ def __str__(self):
342342 return formatted
343343
344344 def __repr__ (self ):
345- return "<{} at {:#x} {!r}>" . format ( self . __class__ . __name__ , id ( self ), self . name )
345+ return f "<{ self . __class__ . __name__ } at { id ( self ) :#x} { self . name !r} >"
346346
347347 def __hash__ (self ):
348- msg = "unhashable type: '{}'" . format ( self .__class__ .__name__ )
348+ msg = f "unhashable type: '{ self .__class__ .__name__ } '"
349349 raise TypeError (msg )
350350
351351 def __eq__ (self , other ):
@@ -442,7 +442,7 @@ def kwargs(self):
442442 return kwargs
443443
444444 def __hash__ (self ):
445- msg = "unhashable type: '{}'" . format ( self .__class__ .__name__ )
445+ msg = f "unhashable type: '{ self .__class__ .__name__ } '"
446446 raise TypeError (msg )
447447
448448 def __eq__ (self , other ):
@@ -501,8 +501,7 @@ def __init__(
501501 for idx , param in enumerate (parameters ):
502502 kind = param .kind
503503 if kind < top_kind :
504- msg = "wrong parameter order: {0} before {1}"
505- msg = msg .format (top_kind , param .kind )
504+ msg = f"wrong parameter order: { top_kind } before { param .kind } "
506505 raise ValueError (msg )
507506 else :
508507 top_kind = kind
@@ -513,7 +512,7 @@ def __init__(
513512 param = param .replace (name = name )
514513
515514 if name in params :
516- msg = "duplicate parameter name: {!r}" . format ( name )
515+ msg = f "duplicate parameter name: { name !r} "
517516 raise ValueError (msg )
518517 params [name ] = param
519518 else :
@@ -527,7 +526,7 @@ def from_function(cls, func):
527526 """Constructs Signature for the given python function"""
528527
529528 if not isinstance (func , types .FunctionType ):
530- raise TypeError ("{ !r} is not a Python function". format ( func ) )
529+ raise TypeError (f" { func !r} is not a Python function" )
531530
532531 Parameter = cls ._parameter_cls
533532
@@ -631,7 +630,7 @@ def replace(self, parameters=_void, return_annotation=_void):
631630 return type (self )(parameters , return_annotation = return_annotation )
632631
633632 def __hash__ (self ):
634- msg = "unhashable type: '{}'" . format ( self .__class__ .__name__ )
633+ msg = f "unhashable type: '{ self .__class__ .__name__ } '"
635634 raise TypeError (msg )
636635
637636 def __eq__ (self , other ):
@@ -708,10 +707,9 @@ def _bind(self, args, kwargs, partial=False):
708707 elif param .name in kwargs :
709708 if param .kind == _POSITIONAL_ONLY :
710709 msg = (
711- "{arg !r} parameter is positional only, "
710+ f" { param . name !r} parameter is positional only, "
712711 "but was passed as a keyword"
713712 )
714- msg = msg .format (arg = param .name )
715713 raise TypeError (msg )
716714 parameters_ex = (param ,)
717715 break
@@ -726,8 +724,7 @@ def _bind(self, args, kwargs, partial=False):
726724 parameters_ex = (param ,)
727725 break
728726 else :
729- msg = "{arg!r} parameter lacking default value"
730- msg = msg .format (arg = param .name )
727+ msg = f"{ param .name !r} parameter lacking default value"
731728 raise TypeError (msg )
732729 else :
733730 # We have a positional argument to process
@@ -751,10 +748,7 @@ def _bind(self, args, kwargs, partial=False):
751748 break
752749
753750 if param .name in kwargs :
754- raise TypeError (
755- "multiple values for argument "
756- "{arg!r}" .format (arg = param .name )
757- )
751+ raise TypeError (f"multiple values for argument { param .name !r} " )
758752
759753 arguments [param .name ] = arg_val
760754
@@ -767,8 +761,8 @@ def _bind(self, args, kwargs, partial=False):
767761 # Signature object (but let's have this check here
768762 # to ensure correct behaviour just in case)
769763 raise TypeError (
770- "{arg !r} parameter is positional only, "
771- "but was passed as a keyword" . format ( arg = param . name )
764+ f" { param . name !r} parameter is positional only, "
765+ "but was passed as a keyword"
772766 )
773767
774768 if param .kind == _VAR_KEYWORD :
@@ -789,9 +783,7 @@ def _bind(self, args, kwargs, partial=False):
789783 and param .kind != _VAR_POSITIONAL
790784 and param .default is _empty
791785 ):
792- raise TypeError (
793- "{arg!r} parameter lacking default value" .format (arg = param_name )
794- )
786+ raise TypeError (f"{ param_name !r} parameter lacking default value" )
795787
796788 else :
797789 arguments [param_name ] = arg_val
@@ -841,10 +833,10 @@ def __str__(self):
841833
842834 result .append (formatted )
843835
844- rendered = "({})" . format ( ", " .join (result ))
836+ rendered = f "({ ', ' .join (result )} )"
845837
846838 if self .return_annotation is not _empty :
847839 anno = formatannotation (self .return_annotation )
848- rendered += " -> {}" . format ( anno )
840+ rendered += f " -> { anno } "
849841
850842 return rendered
0 commit comments