@@ -428,10 +428,16 @@ def packets(self) -> List[bytes]:
428428 first_time = True
429429 debug_enable = LOGGING_IS_ENABLED_FOR (LOGGING_DEBUG )
430430
431- while first_time or self ._has_more_to_add (
432- questions_offset , answer_offset , authority_offset , additional_offset
431+ while (
432+ first_time is True
433+ or self ._has_more_to_add (questions_offset , answer_offset , authority_offset , additional_offset )
434+ is True
433435 ):
434- first_time = False
436+ if first_time :
437+ first_time = False
438+ else :
439+ self ._reset_for_next_packet ()
440+
435441 if debug_enable :
436442 log .debug (
437443 "offsets = questions=%d, answers=%d, authorities=%d, additionals=%d" ,
@@ -471,8 +477,12 @@ def packets(self) -> List[bytes]:
471477 additional_offset ,
472478 )
473479
474- if self .is_query () and self ._has_more_to_add (
475- questions_offset , answer_offset , authority_offset , additional_offset
480+ if (
481+ self .is_query () is True
482+ and self ._has_more_to_add (
483+ questions_offset , answer_offset , authority_offset , additional_offset
484+ )
485+ is True
476486 ):
477487 # https://datatracker.ietf.org/doc/html/rfc6762#section-7.2
478488 if debug_enable : # pragma: no branch
@@ -487,7 +497,6 @@ def packets(self) -> List[bytes]:
487497 self ._insert_short_at_start (self .id )
488498
489499 self .packets_data .append (b'' .join (self .data ))
490- self ._reset_for_next_packet ()
491500
492501 if (
493502 not questions_written
0 commit comments