8000 fix: small internal typing cleanups (#1180) · python-zeroconf/python-zeroconf@f03e511 · GitHub
[go: up one dir, main page]

Skip to content

Commit f03e511

Browse files
authored
fix: small internal typing cleanups (#1180)
1 parent dbd8018 commit f03e511

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/zeroconf/_handlers.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,19 @@ def _has_mcast_within_one_quarter_ttl(self, record: DNSRecord) -> bool:
193193
SHOULD instead multicast the response so as to keep all the peer
194194
caches up to date
195195
"""
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)
197199
return bool(maybe_entry and maybe_entry.is_recent(self._now))
198200

199201
def _has_mcast_record_in_last_second(self, record: DNSRecord) -> bool:
200202
"""Check if an answer was seen in the last second.
201203
Protect the network against excessive packet flooding
202204
https://datatracker.ietf.org/doc/html/rfc6762#section-14
203205
"""
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)
205209
return bool(maybe_entry and self._now - maybe_entry.created < _ONE_SECOND)
206210

207211

@@ -403,7 +407,10 @@ def async_updates_from_response(self, msg: DNSIncoming) -> None:
403407
if record.unique: # https://tools.ietf.org/html/rfc6762#section-10.2
404408
unique_types.add((record.name, record.type, record.class_))
405409

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)
407414
if not record.is_expired(now):
408415
if maybe_entry is not None:
409416
maybe_entry.reset_ttl(record)

0 commit comments

Comments
 (0)
0