Skip to content

Commit 4e40fae

Browse files
authored
fix: remove useless calls in ServiceInfo (#1248)
1 parent a7feade commit 4e40fae

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

src/zeroconf/_services/info.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -427,17 +427,17 @@ def _process_record_threadsafe(self, zc: 'Zeroconf', record: DNSRecord, now: flo
427427
return False
428428

429429
record_key = record.key
430-
if record_key == self.server_key and type(record) is DNSAddress:
430+
record_type = type(record)
431+
if record_key == self.server_key and record_type is DNSAddress:
432+
if TYPE_CHECKING:
433+
assert isinstance(record, DNSAddress)
431434
try:
432435
ip_addr = _cached_ip_addresses(record.address)
433436
except ValueError as ex:
434437
log.warning("Encountered invalid address while processing %s: %s", record, ex)
435438
return False
436439

437440
if type(ip_addr) is IPv4Address:
438-
if self._ipv4_addresses:
439-
self._set_ipv4_addresses_from_cache(zc, now)
440-
441441
ipv4_addresses = self._ipv4_addresses
442442
if ip_addr not in ipv4_addresses:
443443
ipv4_addresses.insert(0, ip_addr)
@@ -448,9 +448,6 @@ def _process_record_threadsafe(self, zc: 'Zeroconf', record: DNSRecord, now: flo
448448

449449
return False
450450

451-
if not self._ipv6_addresses:
452-
self._set_ipv6_addresses_from_cache(zc, now)
453-
454451
ipv6_addresses = self._ipv6_addresses
455452
if ip_addr not in self._ipv6_addresses:
456453
ipv6_addresses.insert(0, ip_addr)
@@ -464,13 +461,18 @@ def _process_record_threadsafe(self, zc: 'Zeroconf', record: DNSRecord, now: flo
464461
if record_key != self.key:
465462
return False
466463

467-
if record.type == _TYPE_TXT and type(record) is DNSText:
464+
if record_type is DNSText:
465+
if TYPE_CHECKING:
466+
assert isinstance(record, DNSText)
468467
self._set_text(record.text)
469468
return True
470469

471-
if record.type == _TYPE_SRV and type(record) is DNSService:
470+
if record_type is DNSService:
471+
if TYPE_CHECKING:
472+
assert isinstance(record, DNSService)
472473
old_server_key = self.server_key
473-
self.name = record.name
474+
self._name = record.name
475+
self.key = record.key
474476
self.server = record.server
475477
self.server_key = record.server_key
476478
self.port = record.port
@@ -577,7 +579,11 @@ def _get_address_records_from_cache_by_type(self, zc: 'Zeroconf', _type: int) ->
577579
"""Get the addresses from the cache."""
578580
if self.server_key is None:
579581
return []
580-
return cast("List[DNSAddress]", zc.cache.get_all_by_details(self.server_key, _type, _CLASS_IN))
582+
if TYPE_CHECKING:
583+
records = cast("List[DNSAddress]", zc.cache.get_all_by_details(self.server_key, _type, _CLASS_IN))
584+
else:
585+
records = zc.cache.get_all_by_details(self.server_key, _type, _CLASS_IN)
586+
return records
581587

582588
def set_server_if_missing(self) -> None:
583589
"""Set the server if it is missing.

0 commit comments

Comments
 (0)