fix: reduce cast calls in service browser (#1164) · python-zeroconf/python-zeroconf@c0d65ae

Original file line numberDiff line numberDiff line change

@@ -157,18 +157,16 @@ def generate_service_query(

157157

question = DNSQuestion(type_, _TYPE_PTR, _CLASS_IN)

158158

question.unicast = qu_question

159159

known_answers = {

160-

cast(DNSPointer, record)

160+

record

161161

for record in zc.cache.get_all_by_details(type_, _TYPE_PTR, _CLASS_IN)

162162

if not record.is_stale(now)

163163

}

164-

if not qu_question and zc.question_history.suppresses(

165-

question, now, cast(Set[DNSRecord], known_answers)

166-

):

164+

if not qu_question and zc.question_history.suppresses(question, now, known_answers):

167165

log.debug("Asking %s was suppressed by the question history", question)

168166

continue

169-

questions_with_known_answers[question] = known_answers

167+

questions_with_known_answers[question] = cast(Set[DNSPointer], known_answers)

170168

if not qu_question:

171-

zc.question_history.add_question_at_time(question, now, cast(Set[DNSRecord], known_answers))

169+

zc.question_history.add_question_at_time(question, now, known_answers)

172170
173171

return _group_ptr_queries_with_known_answers(now, multicast, questions_with_known_answers)

174172