diff --git a/src/zeroconf/_dns.pxd b/src/zeroconf/_dns.pxd index b28f7323..cd4f1f9e 100644 --- a/src/zeroconf/_dns.pxd +++ b/src/zeroconf/_dns.pxd @@ -98,11 +98,14 @@ cdef class DNSNsec(DNSRecord): cdef class DNSRRSet: - cdef _record_sets + cdef cython.list _record_sets cdef cython.dict _lookup @cython.locals(other=DNSRecord) cpdef suppresses(self, DNSRecord record) - @cython.locals(lookup=cython.dict) + @cython.locals( + record=DNSRecord, + record_sets=cython.list, + ) cdef cython.dict _get_lookup(self) diff --git a/src/zeroconf/_dns.py b/src/zeroconf/_dns.py index ada6e9df..34d7fdb2 100644 --- a/src/zeroconf/_dns.py +++ b/src/zeroconf/_dns.py @@ -22,7 +22,7 @@ import enum import socket -from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Union, cast +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union, cast from ._exceptions import AbstractMethodException from ._utils.net import _is_v6_address @@ -516,7 +516,7 @@ class DNSRRSet: __slots__ = ('_record_sets', '_lookup') - def __init__(self, record_sets: Iterable[List[DNSRecord]]) -> None: + def __init__(self, record_sets: List[List[DNSRecord]]) -> None: """Create an RRset from records sets.""" self._record_sets = record_sets self._lookup: Optional[Dict[DNSRecord, float]] = None @@ -530,7 +530,10 @@ def _get_lookup(self) -> Dict[DNSRecord, float]: """Return the lookup table, building it if needed.""" if self._lookup is None: # Build the hash table so we can lookup the record ttl - self._lookup = {record: record.ttl for record_sets in self._record_sets for record in record_sets} + self._lookup = {} + for record_sets in self._record_sets: + for record in record_sets: + self._lookup[record] = record.ttl return self._lookup def suppresses(self, record: _DNSRecord) -> bool: diff --git a/src/zeroconf/_handlers.py b/src/zeroconf/_handlers.py index 5cb192de..bf1f6acb 100644 --- a/src/zeroconf/_handlers.py +++ b/src/zeroconf/_handlers.py @@ -322,7 +322,7 @@ def async_response( # pylint: disable=unused-argument This function must be run in the event loop as it is not threadsafe. """ - known_answers = DNSRRSet(msg.answers for msg in msgs if not msg.is_probe) + known_answers = DNSRRSet([msg.answers for msg in msgs if not msg.is_probe]) query_res = _QueryResponse(self.cache, msgs) for msg in msgs: