4141_RECENT_TIME_MS = 250
4242
4343
44+ int_ = int
45+ float_ = float
46+ int_or_float_ = Union [int , float ]
47+
4448if TYPE_CHECKING :
4549 from ._protocol .incoming import DNSIncoming
4650 from ._protocol .outgoing import DNSOutgoing
@@ -159,7 +163,7 @@ class DNSRecord(DNSEntry):
159163
160164 # TODO: Switch to just int ttl
161165 def __init__ (
162- self , name : str , type_ : int , class_ : int , ttl : Union [ float , int ] , created : Optional [float ] = None
166+ self , name : str , type_ : int , class_ : int , ttl : int_or_float_ , created : Optional [float ] = None
163167 ) -> None :
164168 super ().__init__ (name , type_ , class_ )
165169 self .ttl = ttl
@@ -172,20 +176,23 @@ def __eq__(self, other: Any) -> bool: # pylint: disable=no-self-use
172176 def suppressed_by (self , msg : 'DNSIncoming' ) -> bool :
173177 """Returns true if any answer in a message can suffice for the
174178 information held in this record."""
175- return any (self ._suppressed_by_answer (record ) for record in msg .answers )
179+ for record in msg .answers :
180+ if self ._suppressed_by_answer (record ):
181+ return True
182+ return False
176183
177184 def _suppressed_by_answer (self , other ) -> bool : # type: ignore[no-untyped-def]
178185 """Returns true if another record has same name, type and class,
179186 and if its TTL is at least half of this record's."""
180- return self == other and other .ttl > (self .ttl / 2 )
187+ return bool ( self == other and other .ttl > (self .ttl / 2 ) )
181188
182- def get_expiration_time (self , percent : int ) -> float :
189+ def get_expiration_time (self , percent : int_ ) -> float :
183190 """Returns the time at which this record will have expired
184191 by a certain percentage."""
185192 return self .created + (percent * self .ttl * 10 )
186193
187194 # TODO: Switch to just int here
188- def get_remaining_ttl (self , now : float ) -> Union [ int , float ] :
195+ def get_remaining_ttl (self , now : float ) -> int_or_float_ :
189196 """Returns the remaining TTL in seconds."""
190197 return max (0 , millis_to_seconds ((self .created + (_EXPIRE_FULL_TIME_MS * self .ttl )) - now ))
191198
@@ -206,7 +213,7 @@ def reset_ttl(self, other: 'DNSRecord') -> None:
206213 another record."""
207214 self .set_created_ttl (other .created , other .ttl )
208215
209- def set_created_ttl (self , created : float , ttl : Union [ float , int ] ) -> None :
216+ def set_created_ttl (self , created : float_ , ttl : int_or_float_ ) -> None :
210217 """Set the created and ttl of a record."""
211218 self .created = created
212219 self .ttl = ttl
@@ -403,7 +410,7 @@ def __init__(
403410 name : str ,
404411 type_ : int ,
405412 class_ : int ,
406- ttl : Union [ float , int ] ,
413+ ttl : int_or_float_ ,
407414 priority : int ,
408415 weight : int ,
409416 port : int ,
0 commit comments