@@ -193,15 +193,19 @@ def _has_mcast_within_one_quarter_ttl(self, record: DNSRecord) -> bool:
193
193
SHOULD instead multicast the response so as to keep all the peer
194
194
caches up to date
195
195
"""
196
- maybe_entry = self ._cache .async_get_unique (cast (_UniqueRecordsType , record ))
196
+ if TYPE_CHECKING :
197
+ record = cast (_UniqueRecordsType , record )
198
+ maybe_entry = self ._cache .async_get_unique (record )
197
199
return bool (maybe_entry and maybe_entry .is_recent (self ._now ))
198
200
199
201
def _has_mcast_record_in_last_second (self , record : DNSRecord ) -> bool :
200
202
"""Check if an answer was seen in the last second.
201
203
Protect the network against excessive packet flooding
202
204
https://datatracker.ietf.org/doc/html/rfc6762#section-14
203
205
"""
204
- maybe_entry = self ._cache .async_get_unique (cast (_UniqueRecordsType , record ))
206
+ if TYPE_CHECKING :
207
+ record = cast (_UniqueRecordsType , record )
208
+ maybe_entry = self ._cache .async_get_unique (record )
205
209
return bool (maybe_entry and self ._now - maybe_entry .created < _ONE_SECOND )
206
210
207
211
@@ -403,7 +407,10 @@ def async_updates_from_response(self, msg: DNSIncoming) -> None:
403
407
if record .unique : # https://tools.ietf.org/html/rfc6762#section-10.2
404
408
unique_types .add ((record .name , record .type , record .class_ ))
405
409
406
- maybe_entry = self .cache .async_get_unique (cast (_UniqueRecordsType , record ))
410
+ if TYPE_CHECKING :
411
+ record = cast (_UniqueRecordsType , record )
412
+
413
+ maybe_entry = self .cache .async_get_unique (record )
407
414
if not record .is_expired (now ):
408
415
if maybe_entry is not None :
409
416
maybe_entry .reset_ttl (record )
0 commit comments