@@ -313,14 +313,14 @@ def _read_stream(stream: IO[bytes], length: int) -> bytes:
313313 raise ValueError ("length must be >= 0" , length )
314314 data = stream .read (length )
315315 if len (data ) != length :
316- raise FieldError ("expected %d , found %d" % ( length , len (data )) )
316+ raise FieldError (f "expected { length } , found { len (data )} " )
317317 return data
318318
319319def _write_stream (stream : IO [bytes ], length : int , data : bytes ) -> None :
320320 if length < 0 :
321321 raise ValueError ("length must be >= 0" , length )
322322 if len (data ) != length :
323- raise FieldError ("expected %d , found %d" % ( length , len (data )) )
323+ raise FieldError (f "expected { length } , found { len (data )} " )
324324 stream .write (data )
325325
326326class StaticField (Construct ):
@@ -452,12 +452,12 @@ def _parse(self, stream: IO[bytes], context: Container) -> ListContainer:
452452 obj .append (self .subcon ._parse (stream , context ))
453453 c += 1
454454 except ConstructError as ex :
455- raise ArrayError ("expected %d , found %d" % ( count , c ) , ex )
455+ raise ArrayError (f "expected { count } , found { c } " , ex )
456456 return obj
457457 def _build (self , obj : Any , stream : IO [bytes ], context : Container ) -> None :
458458 count = self .countfunc (context )
459459 if len (obj ) != count :
460- raise ArrayError ("expected %d , found %d" % ( count , len (obj )) )
460+ raise ArrayError (f "expected { count } , found { len (obj )} " )
461461 if self .subcon .conflags & self .FLAG_COPY_CONTEXT :
462462 for subobj in obj :
463463 self .subcon ._build (subobj , stream , context .__copy__ ())
@@ -534,14 +534,12 @@ def _parse(self, stream: IO[bytes], context: Container) -> ListContainer:
534534 c += 1
535535 except ConstructError as ex :
536536 if c < self .mincount :
537- raise RangeError ("expected %d to %d, found %d" %
538- (self .mincount , self .maxcout , c ), ex )
537+ raise RangeError (f"expected { self .mincount } to { self .maxcout } , found { c } " , ex )
539538 stream .seek (pos )
540539 return obj
541540 def _build (self , obj : Any , stream : IO [bytes ], context : Container ) -> None :
542541 if len (obj ) < self .mincount or len (obj ) > self .maxcout :
543- raise RangeError ("expected %d to %d, found %d" %
544- (self .mincount , self .maxcout , len (obj )))
542+ raise RangeError (f"expected { self .mincount } to { self .maxcout } , found { len (obj )} " )
545543 cnt = 0
546544 try :
547545 if self .subcon .conflags & self .FLAG_COPY_CONTEXT :
@@ -558,8 +556,7 @@ def _build(self, obj: Any, stream: IO[bytes], context: Container) -> None:
558556 cnt += 1
559557 except ConstructError as ex :
560558 if cnt < self .mincount :
561- raise RangeError ("expected %d to %d, found %d" %
562- (self .mincount , self .maxcout , len (obj )), ex )
559+ raise RangeError (f"expected { self .mincount } to { self .maxcout } , found { len (obj )} " , ex )
563560 def _sizeof (self , context : Container ) -> int :
564561 raise SizeofError ("can't calculate size" )
565562
0 commit comments