fix: small internal typing cleanups by bdraco · Pull Request #1180 · python-zeroconf/python-zeroconf

Expand Up @@ -193,15 +193,19 @@ def _has_mcast_within_one_quarter_ttl(self, record: DNSRecord) -> bool: SHOULD instead multicast the response so as to keep all the peer caches up to date """ maybe_entry = self._cache.async_get_unique(cast(_UniqueRecordsType, record)) if TYPE_CHECKING: record = cast(_UniqueRecordsType, record) maybe_entry = self._cache.async_get_unique(record) return bool(maybe_entry and maybe_entry.is_recent(self._now))
def _has_mcast_record_in_last_second(self, record: DNSRecord) -> bool: """Check if an answer was seen in the last second. Protect the network against excessive packet flooding https://datatracker.ietf.org/doc/html/rfc6762#section-14 """ maybe_entry = self._cache.async_get_unique(cast(_UniqueRecordsType, record)) if TYPE_CHECKING: record = cast(_UniqueRecordsType, record) maybe_entry = self._cache.async_get_unique(record) return bool(maybe_entry and self._now - maybe_entry.created < _ONE_SECOND)

Expand Down Expand Up @@ -403,7 +407,10 @@ def async_updates_from_response(self, msg: DNSIncoming) -> None: if record.unique: # https://tools.ietf.org/html/rfc6762#section-10.2 unique_types.add((record.name, record.type, record.class_))
maybe_entry = self.cache.async_get_unique(cast(_UniqueRecordsType, record)) if TYPE_CHECKING: record = cast(_UniqueRecordsType, record)
maybe_entry = self.cache.async_get_unique(record) if not record.is_expired(now): if maybe_entry is not None: maybe_entry.reset_ttl(record) Expand Down