Skip to content

Commit e7efb1a

Browse files
committed
chore: refactor
1 parent 26738b4 commit e7efb1a

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

src/zeroconf/_cache.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,8 @@ def _async_add(self, record: _DNSRecord) -> bool:
8686
# replaces any existing records that are __eq__ to each other which
8787
# removes the risk that accessing the cache from the wrong
8888
# direction would return the old incorrect entry.
89-
if record.key not in self.cache:
89+
if (store := self.cache.get(record.key)) is None:
9090
store = self.cache[record.key] = {}
91-
else:
92-
store = self.cache[record.key]
9391
new = record not in store and not isinstance(record, DNSNsec)
9492
store[record] = record
9593
when = record.created + (record.ttl * 1000)
@@ -100,10 +98,8 @@ def _async_add(self, record: _DNSRecord) -> bool:
10098

10199
if isinstance(record, DNSService):
102100
service_record = record
103-
if service_record.server_key not in self.service_cache:
101+
if (service_store := self.service_cache.get(service_record.server_key)) is None:
104102
service_store = self.service_cache[service_record.server_key] = {}
105-
else:
106-
service_store = self.service_cache[service_record.server_key]
107103
service_store[service_record] = service_record
108104
return new
109105

0 commit comments

Comments
 (0)