@@ -180,10 +180,10 @@ def return_value(self, buf: memoryview, offset: int, _parent: Optional['WrappedC
180180 if self .enum :
181181 return self .enum .find_name_by_value (
182182 rv .decode ("ascii" ) if isinstance (rv , bytes ) else str (rv ))
183- elif self .set_ :
183+ if self .set_ :
184184 return self .set_ .find_name_by_value (
185185 rv .decode ("ascii" ) if isinstance (rv , bytes ) else str (rv ))
186- elif self .value .endswith ("s" ):
186+ if self .value .endswith ("s" ):
187187 return rv .split (b'\x00 ' , 1 )[0 ].decode ('ascii' , errors = 'ignore' ).strip ()
188188
189189 return rv
@@ -197,12 +197,11 @@ def unpack(self, buf: memoryview):
197197 def __repr__ (self ):
198198 if self .enum :
199199 return f"{ self .enum .name } @{ self .offset } "
200- elif isinstance (self .value , WrappedComposite ):
200+ if isinstance (self .value , WrappedComposite ):
201201 return f"{ self .value .name } @{ self .offset } "
202- elif self .value in FORMAT_TO_TYPE :
202+ if self .value in FORMAT_TO_TYPE :
203203 return f"{ FORMAT_TO_TYPE [self .value ].value } @{ self .offset } "
204- else :
205- return f"{ self .value } @{ self .offset } "
204+ return f"{ self .value } @{ self .offset } "
206205
207206
208207@dataclass
@@ -232,8 +231,7 @@ def find_value_by_name(self, name: Optional[str]) -> str:
232231 val = next (x for x in self .valid_values if x .name == name ).value
233232 if self .encodingType == EnumEncodingType .CHAR or (isinstance (self .encodingType , Type ) and self .encodingType .primitiveType == PrimitiveType .CHAR ):
234233 return val .encode ()
235- else :
236- return int (val )
234+ return int (val )
237235
238236 def find_name_by_value (self , val : str ) -> str :
239237 if val not in (x .value for x in self .valid_values ):
@@ -260,7 +258,7 @@ def size(self):
260258 else :
261259 sz += FORMAT_SIZES [t .primitiveType ]
262260 else :
263- assert ( isinstance (t , Composite ) )
261+ assert isinstance (t , Composite )
264262 sz += t .size ()
265263 return sz
266264
@@ -314,8 +312,7 @@ def __init__(self, name: str, id_: str, type_: Union[PrimitiveType, str]):
314312 def __repr__ (self ):
315313 if isinstance (self .type , PrimitiveType ):
316314 return f"<{ self .name } ({ self .type .value } )>"
317- else :
318- return f"<{ self .name } ({ self .type } )>"
315+ return f"<{ self .name } ({ self .type } )>"
319316
320317
321318@dataclass
@@ -587,10 +584,10 @@ def _unpack_format(
587584 buffer_cursor .val += FORMAT_SIZES [type_ ]
588585 return prefix + FORMAT [type_ ]
589586
590- elif isinstance (type_ , Field ):
587+ if isinstance (type_ , Field ):
591588 return _unpack_format (schema , type_ .type , '' , buffer , buffer_cursor )
592589
593- elif isinstance (type_ , Group ):
590+ if isinstance (type_ , Group ):
594591 if len (buffer [buffer_cursor .val :]) == 0 :
595592 return ''
596593
@@ -608,7 +605,7 @@ def _unpack_format(
608605
609606 return rv
610607
611- elif isinstance (type_ , Type ):
608+ if isinstance (type_ , Type ):
612609 if type_ .presence == Presence .CONSTANT :
613610 return ''
614611 if type_ .padding > 0 :
@@ -619,12 +616,12 @@ def _unpack_format(
619616 if buffer_cursor :
620617 buffer_cursor .val += type_ .length
621618 return prefix + f"{ type_ .length } s"
622- else :
623- if buffer_cursor :
624- buffer_cursor .val += FORMAT_SIZES [type_ .primitiveType ]
625- return prefix + FORMAT [type_ .primitiveType ]
626619
627- elif isinstance (type_ , (Set , Enum )):
620+ if buffer_cursor :
621+ buffer_cursor .val += FORMAT_SIZES [type_ .primitiveType ]
622+ return prefix + FORMAT [type_ .primitiveType ]
623+
624+ if isinstance (type_ , (Set , Enum )):
628625 if type_ .presence == Presence .CONSTANT :
629626 return ''
630627 if isinstance (type_ .encodingType , (PrimitiveType , EnumEncodingType , SetEncodingType )):
@@ -640,7 +637,7 @@ def _unpack_format(
640637
641638 return _unpack_format (schema , type_ .encodingType , '' , buffer , buffer_cursor )
642639
643- elif isinstance (type_ , Composite ):
640+ if isinstance (type_ , Composite ):
644641 return prefix + '' .join (_unpack_format (schema , t , '' , buffer , buffer_cursor ) for t in type_ .types )
645642
646643
@@ -832,8 +829,7 @@ def _resolve_ref_type(t: RefType, composite: Composite):
832829 if isinstance (parent , Schema ):
833830 if t .type in parent .types :
834831 return parent .types [t .type ]
835- else :
836- assert False , f"RefType '{ t .type } ' not found in schema"
832+ assert False , f"RefType '{ t .type } ' not found in schema"
837833 else :
838834 t1 = next ((x for x in parent .types if x .name == t .type ), None )
839835 if t1 is not None :
@@ -1177,7 +1173,7 @@ def _parse_schema_impl(doc, only_tags: Optional[list] = None, extra_types: Optio
11771173 assert isinstance (stack [- 1 ], Set )
11781174 stack [- 1 ].choices .append (x )
11791175
1180- elif tag == " field" or tag == " data" :
1176+ elif tag in ( ' field' , ' data' ) :
11811177 if action == "start" :
11821178 assert len (elem ) == 0
11831179
0 commit comments