@@ -186,7 +186,7 @@ def f(b):
186186 def __init__ (self , x = None ):
187187 self .x = x
188188 def __repr__ (self ): # pragma: no cover
189- return "box({})" . format ( repr (self .x ))
189+ return f "box({ repr (self .x )} )"
190190 def __contains__ (self , x ):
191191 return self .x == x
192192 def __iter__ (self ):
@@ -237,7 +237,7 @@ def __init__(self, x=None):
237237 self ._default = x
238238 def __repr__ (self ): # pragma: no cover
239239 """**WARNING**: the repr shows only the content seen by the current thread."""
240- return "ThreadLocalBox({})" . format ( repr (self .get ()))
240+ return f "ThreadLocalBox({ repr (self .get ())} )"
241241 def __contains__ (self , x ):
242242 return self .get () == x
243243 def __iter__ (self ):
@@ -280,7 +280,7 @@ class Some:
280280 def __init__ (self , x = None ):
281281 self .x = x
282282 def __repr__ (self ): # pragma: no cover
283- return "Some({})" . format ( repr (self .x ))
283+ return f "Some({ repr (self .x )} )"
284284 def __contains__ (self , x ):
285285 return self .x == x
286286 def __iter__ (self ):
@@ -304,7 +304,7 @@ def unbox(b):
304304 If `b` is not a `box` (or `ThreadLocalBox` or `Some`), raises `TypeError`.
305305 """
306306 if not isinstance (b , (box , Some )):
307- raise TypeError ("Expected box, got {} with value {}" . format ( type ( b ), repr (b )) )
307+ raise TypeError (f "Expected box, got { type ( b ) } with value { repr (b )} " )
308308 return b .get ()
309309
310310class Shim :
@@ -353,7 +353,7 @@ class Shim:
353353 """
354354 def __init__ (self , thebox , fallback = None ):
355355 if not isinstance (thebox , box ):
356- raise TypeError ("Expected box, got {} with value {}" . format ( type ( thebox ), repr (thebox )) )
356+ raise TypeError (f "Expected box, got { type ( thebox ) } with value { repr (thebox )} " )
357357 self ._shim_box = thebox
358358 self ._shim_fallback = fallback
359359 def __getattr__ (self , k ):
@@ -456,7 +456,7 @@ def __init__(self, *ms, **bindings):
456456
457457 @wraps (dict .__repr__ )
458458 def __repr__ (self ): # pragma: no cover
459- return "frozendict({})" . format ( self ._data .__repr__ ())
459+ return f "frozendict({ self ._data .__repr__ ()} )"
460460
461461 def __hash__ (self ):
462462 return hash (frozenset (self .items ()))
@@ -547,7 +547,7 @@ def _lowlevel_repr(self): # pragma: no cover
547547 def __str__ (self ): # pragma: no cover
548548 return str (self ._lowlevel_repr ())
549549 def __repr__ (self ): # pragma: no cover
550- return "{:s}({!r})" . format ( self .__class__ .__name__ , self ._lowlevel_repr ())
550+ return f" { self .__class__ .__name__ } ( { self ._lowlevel_repr ()!r } )"
551551
552552 def __eq__ (self , other ):
553553 if other is self :
@@ -643,7 +643,7 @@ def __getitem__(self, k):
643643 return ctor (self .seq , k )
644644 return ctor (self , k )
645645 elif isinstance (k , tuple ):
646- raise TypeError ("multidimensional subscripting not supported; got {}" . format ( repr (k )) )
646+ raise TypeError (f "multidimensional subscripting not supported; got { repr (k )} " )
647647 else :
648648 data , r = self ._update_cache ()
649649 n = len (r )
@@ -709,7 +709,7 @@ def __setitem__(self, k, v):
709709 for j , item in zip (r [k ], vs ):
710710 data [j ] = item
711711 elif isinstance (k , tuple ):
712- raise TypeError ("multidimensional subscripting not supported; got {}" . format ( repr (k )) )
712+ raise TypeError (f "multidimensional subscripting not supported; got { repr (k )} " )
713713 else :
714714 n = len (r )
715715 if k >= n or k < - n :
@@ -736,7 +736,7 @@ class ShadowedSequence(Sequence, _StrReprEqMixin):
736736 """
737737 def __init__ (self , seq , ix = None , v = None ):
738738 if ix is not None and not isinstance (ix , (slice , int )):
739- raise TypeError ("ix: expected slice or int, got {} with value {}" . format ( type ( ix ), ix ) )
739+ raise TypeError (f "ix: expected slice or int, got { type ( ix ) } with value { ix } " )
740740 self .seq = seq
741741 self .ix = ix
742742 self .v = v
@@ -767,7 +767,7 @@ def __getitem__(self, k):
767767 ctor = tuple if hasattr (cls , "_make" ) else cls # slice of namedtuple -> tuple
768768 return ctor (self ._getone (j ) for j in range (n )[k ])
769769 elif isinstance (k , tuple ):
770- raise TypeError ("multidimensional subscripting not supported; got {}" . format ( repr (k )) )
770+ raise TypeError (f "multidimensional subscripting not supported; got { repr (k )} " )
771771 else :
772772 if k >= n or k < - n :
773773 raise IndexError ("ShadowedSequence index out of range" )
@@ -782,7 +782,7 @@ def _getone(self, k):
782782 # we already know k is in ix, so skip validation for speed.
783783 i = _index_in_slice (k , ix , n , _validate = False )
784784 if i >= len (self .v ):
785- raise IndexError ("Replacement sequence too short; attempted to access index {} with len {} (items: {})" . format ( i , len ( self .v ), self . v ) )
785+ raise IndexError (f "Replacement sequence too short; attempted to access index { i } with len { len ( self . v ) } (items: { self .v } )" )
786786 return self .v [i ]
787787 return self .seq [k ] # not in slice
788788
@@ -801,9 +801,9 @@ def in_slice(i, s, l=None):
801801 ValueError. (A negative ``s.step`` by itself does not need ``l``.)
802802 """
803803 if not isinstance (s , (slice , int )):
804- raise TypeError ("s must be slice or int, got {} with value {}" . format ( type ( s ), s ) )
804+ raise TypeError (f "s must be slice or int, got { type ( s ) } with value { s } " )
805805 if not isinstance (i , int ):
806- raise TypeError ("i must be int, got {} with value {}" . format ( type ( i ), i ) )
806+ raise TypeError (f "i must be int, got { type ( i ) } with value { i } " )
807807 wrap = _make_negidx_converter (l )
808808 i = wrap (i )
809809 if isinstance (s , int ):
@@ -837,9 +837,9 @@ def _index_in_slice(i, s, n=None, _validate=True): # n: length of sequence bein
837837def _make_negidx_converter (n ): # n: length of sequence being indexed
838838 if n is not None :
839839 if not isinstance (n , int ):
840- raise TypeError ("n must be int, got {} with value {}" . format ( type ( n ), n ) )
840+ raise TypeError (f "n must be int, got { type ( n ) } with value { n } " )
841841 if n <= 0 :
842- raise ValueError ("n must be an int >= 1, got {}" . format ( n ) )
842+ raise ValueError (f "n must be an int >= 1, got { n } " )
843843 def apply_conversion (k ):
844844 return k % n
845845 else :
@@ -852,12 +852,12 @@ def convert(k):
852852 # layers protect against having to check here, but since the
853853 # `convert` function is returned to the caller, let's be
854854 # careful.
855- raise TypeError ("k must be int, got {} with value {}" . format ( type ( k ), k ) ) # pragma: no cover
855+ raise TypeError (f "k must be int, got { type ( k ) } with value { k } " ) # pragma: no cover
856856 # Almost standard semantics for negative indices. Usually -n < k < n,
857857 # but here we must allow for conversion of the end position, for
858858 # which the last valid value is one past the end.
859859 if n is not None and not - n <= k <= n :
860- raise IndexError ("Should have -n <= k <= n, but n = {}, and k = {}" . format ( n , k ) )
860+ raise IndexError (f "Should have -n <= k <= n, but n = { n } , and k = { k } " )
861861 return apply_conversion (k ) if k < 0 else k
862862 return convert
863863
@@ -868,7 +868,7 @@ def _canonize_slice(s, n=None, wrap=None): # convert negatives, inject defaults
868868 # used elsewhere. (And, it's already possible that some internal caller
869869 # incorrectly uses the no-check mode of the internal implementation function
870870 # `_index_in_slice`.)
871- raise TypeError ("s must be slice, got {} with value {}" . format ( type ( s ), s ) ) # pragma: no cover
871+ raise TypeError (f "s must be slice, got { type ( s ) } with value { s } " ) # pragma: no cover
872872
873873 step = s .step if s .step is not None else + 1 # no "s.step or +1"; someone may try step=0
874874 if step == 0 :
0 commit comments