FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: build with cython 3.3.0 (#1820) · python-zeroconf/python-zeroconf@df947b2 · GitHub

Commit df947b2

Browse files
authored
fix: build with cython 3.3.0 (#1820)
1 parent b342aab commit df947b2

9 files changed

Lines changed: 32 additions & 23 deletions

File tree

‎src/zeroconf/_cache.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
_UNIQUE_RECORD_TYPES = (DNSAddress, DNSHinfo, DNSPointer, DNSText, DNSService)
4343
_UniqueRecordsType = DNSAddress | DNSHinfo | DNSPointer | DNSText | DNSService
4444
_DNSRecordCacheType = dict[str, dict[DNSRecord, DNSRecord]]
45+
_UniqueType = tuple[str, int, int]
4546
_DNSRecord = DNSRecord
4647
_str = str
4748
_float = float
@@ -324,7 +325,7 @@ def names(self) -> list[str]:
324325

325326
def async_mark_unique_records_older_than_1s_to_expire(
326327
self,
327-
unique_types: set[tuple[_str, _int, _int]],
328+
unique_types: set[_UniqueType],
328329
answers: Iterable[DNSRecord],
329330
now: _float,
330331
) -> None:

‎src/zeroconf/_handlers/query_handler.pxd‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ cdef class QueryHandler:
9696
question=DNSQuestion,
9797
answer_set=cython.dict,
9898
known_answers=DNSRRSet,
99-
known_answers_set=cython.set,
10099
is_unicast=bint,
101100
is_probe=object,
102101
now=double

‎src/zeroconf/_handlers/query_handler.py‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161

6262
_int = int
6363
_str = str
64+
_ServiceInfo = ServiceInfo
65+
_DNSIncoming = DNSIncoming
6466

6567
_ANSWER_STRATEGY_SERVICE_TYPE_ENUMERATION = 0
6668
_ANSWER_STRATEGY_POINTER = 1
@@ -212,7 +214,7 @@ def __init__(self, zc: Zeroconf) -> None:
212214

213215
def _add_service_type_enumeration_query_answers(
214216
self,
215-
types: list[str],
217+
types: list[_str],
216218
answer_set: _AnswerWithAdditionalsType,
217219
known_answers: DNSRRSet,
218220
) -> None:
@@ -234,7 +236,7 @@ def _add_service_type_enumeration_query_answers(
234236

235237
def _add_pointer_answers(
236238
self,
237-
services: list[ServiceInfo],
239+
services: list[_ServiceInfo],
238240
answer_set: _AnswerWithAdditionalsType,
239241
known_answers: DNSRRSet,
240242
) -> None:
@@ -253,7 +255,7 @@ def _add_pointer_answers(
253255

254256
def _add_address_answers(
255257
self,
256-
services: list[ServiceInfo],
258+
services: list[_ServiceInfo],
257259
answer_set: _AnswerWithAdditionalsType,
258260
known_answers: DNSRRSet,
259261
type_: _int,
@@ -284,8 +286,8 @@ def _answer_question(
284286
self,
285287
question: DNSQuestion,
286288
strategy_type: _int,
287-
types: list[str],
288-
services: list[ServiceInfo],
289+
types: list[_str],
290+
services: list[_ServiceInfo],
289291
known_answers: DNSRRSet,
290292
) -> _AnswerWithAdditionalsType:
291293
"""Answer a question."""
@@ -313,7 +315,7 @@ def _answer_question(
313315
return answer_set
314316

315317
def async_response( # pylint: disable=unused-argument
316-
self, msgs: list[DNSIncoming], ucast_source: bool
318+
self, msgs: list[_DNSIncoming], ucast_source: bool
317319
) -> QuestionAnswers | None:
318320
"""Deal with incoming query packets. Provides a response if possible.
319321
@@ -435,7 +437,7 @@ def _get_answer_strategies(
435437

436438
def handle_assembled_query(
437439
self,
438-
packets: list[DNSIncoming],
440+
packets: list[_DNSIncoming],
439441
addr: _str,
440442
port: _int,
441443
transport: _WrappedTransport,

‎src/zeroconf/_handlers/record_manager.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
from .._core import Zeroconf
3838

3939
_float = float
40+
_RecordUpdate = RecordUpdate
41+
_DNSQuestion = DNSQuestion
4042

4143

4244
class RecordManager:
@@ -50,7 +52,7 @@ def __init__(self, zeroconf: Zeroconf) -> None:
5052
self.cache = zeroconf.cache
5153
self.listeners: set[RecordUpdateListener] = set()
5254

53-
def async_updates(self, now: _float, records: list[RecordUpdate]) -> None:
55+
def async_updates(self, now: _float, records: list[_RecordUpdate]) -> None:
5456
"""Used to notify listeners of new information that has updated
5557
a record.
5658
@@ -190,7 +192,7 @@ def async_add_listener(
190192
self._async_update_matching_records(listener, questions)
191193

192194
def _async_update_matching_records(
193-
self, listener: RecordUpdateListener, questions: list[DNSQuestion]
195+
self, listener: RecordUpdateListener, questions: list[_DNSQuestion]
194196
) -> None:
195197
"""Calls back any existing entries in the cache that answer the question.
196198

‎src/zeroconf/_protocol/incoming.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def _read_name(self) -> str:
455455
return name
456456

457457
def _decode_labels_at_offset(
458-
self, off: _int, labels: list[str], seen_pointers: set[int], depth: _int
458+
self, off: _int, labels: list[_str], seen_pointers: set[_int], depth: _int
459459
) -> int:
460460
# This is a tight loop that is called frequently, small optimizations can make a difference.
461461
if depth > MAX_DNS_LABELS:

‎src/zeroconf/_services/browser.pxd‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ cpdef list generate_service_query(
5656
)
5757

5858

59-
@cython.locals(answer=DNSPointer, query_buckets=list, question=DNSQuestion, max_compressed_size=cython.uint, max_bucket_size=cython.uint, query_bucket=_DNSPointerOutgoingBucket)
59+
@cython.locals(answer=DNSPointer, question=DNSQuestion, max_compressed_size=cython.uint, max_bucket_size=cython.uint, query_bucket=_DNSPointerOutgoingBucket)
6060
cdef list _group_ptr_queries_with_known_answers(double now_millis, bint multicast, cython.dict question_with_known_answers)
6161

6262

@@ -92,7 +92,7 @@ cdef class QueryScheduler:
9292

9393
cpdef void _process_startup_queries(self)
9494

95-
@cython.locals(query=_ScheduledPTRQuery, next_scheduled=_ScheduledPTRQuery, next_when=double)
95+
@cython.locals(query=_ScheduledPTRQuery, next_when=double)
9696
cpdef void _process_ready_types(self)
9797

9898
cpdef void async_send_ready_queries(self, bint first_request, double now_millis, set ready_types)

‎src/zeroconf/_services/browser.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@
9595
str_ = str
9696

9797
_QuestionWithKnownAnswers = dict[DNSQuestion, set[DNSPointer]]
98+
DNSPointer_ = DNSPointer
99+
DNSOutgoing_ = DNSOutgoing
100+
RecordUpdate_ = RecordUpdate
98101

99102
heappop = heapq.heappop
100103
heappush = heapq.heappush
@@ -193,7 +196,7 @@ def __init__(self, now_millis: float, multicast: bool) -> None:
193196
self.out = DNSOutgoing(_FLAGS_QR_QUERY, multicast)
194197
self.bytes = 0
195198

196-
def add(self, max_compressed_size: int_, question: DNSQuestion, answers: set[DNSPointer]) -> None:
199+
def add(self, max_compressed_size: int_, question: DNSQuestion, answers: set[DNSPointer_]) -> None:
197200
"""Add a new set of questions and known answers to the outgoing."""
198201
self.out.add_question(question)
199202
for answer in answers:
@@ -259,10 +262,10 @@ def _group_ptr_queries_with_known_answers(
259262
def generate_service_query(
260263
zc: Zeroconf,
261264
now_millis: float_,
262-
types_: set[str],
265+
types_: set[str_],
263266
multicast: bool,
264267
question_type: DNSQuestionType | None,
265-
) -> list[DNSOutgoing]:
268+
) -> list[DNSOutgoing_]:
266269
"""Generate a service query for sending with zeroconf.send."""
267270
questions_with_known_answers: _QuestionWithKnownAnswers = {}
268271
qu_question = not multicast if question_type is None else question_type is QU_QUESTION
@@ -533,7 +536,7 @@ def _process_ready_types(self) -> None:
533536
self._next_run = self._loop.call_at(millis_to_seconds(next_when_millis), self._process_ready_types)
534537

535538
def async_send_ready_queries(
536-
self, first_request: bool, now_millis: float_, ready_types: set[str]
539+
self, first_request: bool, now_millis: float_, ready_types: set[str_]
537540
) -> None:
538541
"""Send any ready queries."""
539542
# If they did not specify and this is the first request, ask QU questions
@@ -665,7 +668,7 @@ def _enqueue_callback(
665668
):
666669
self._pending_handlers[key] = state_change
667670

668-
def async_update_records(self, zc: Zeroconf, now: float_, records: list[RecordUpdate]) -> None:
671+
def async_update_records(self, zc: Zeroconf, now: float_, records: list[RecordUpdate_]) -> None:
669672
"""Callback invoked by Zeroconf when new information arrives.
670673
671674
Updates information required by browser in the Zeroconf cache.

‎src/zeroconf/_services/info.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
float_ = float
100100
int_ = int
101101
str_ = str
102+
RecordUpdate_ = RecordUpdate
102103

103104
QU_QUESTION = DNSQuestionType.QU
104105
QM_QUESTION = DNSQuestionType.QM
@@ -547,7 +548,7 @@ def _set_ipv4_addresses_from_cache(self, zc: Zeroconf, now: float_) -> None:
547548
else:
548549
self._ipv4_addresses = self._get_ip_addresses_from_cache_lifo(zc, now, _TYPE_A)
549550

550-
def async_update_records(self, zc: Zeroconf, now: float_, records: list[RecordUpdate]) -> None:
551+
def async_update_records(self, zc: Zeroconf, now: float_, records: list[RecordUpdate_]) -> None:
551552
"""Updates service information from a DNS record.
552553
553554
This method will be run in the event loop.
@@ -741,7 +742,7 @@ def dns_nsec(self, missing_types: list[int], override_ttl: int_ | None = None) -
741742
"""Return DNSNsec from ServiceInfo."""
742743
return self._dns_nsec(missing_types, override_ttl)
743744

744-
def _dns_nsec(self, missing_types: list[int], override_ttl: int_ | None) -> DNSNsec:
745+
def _dns_nsec(self, missing_types: list[int_], override_ttl: int_ | None) -> DNSNsec:
745746
"""Return DNSNsec from ServiceInfo."""
746747
return DNSNsec(
747748
self._name,

‎src/zeroconf/_services/registry.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from .info import ServiceInfo
2727

2828
_str = str
29+
_ServiceInfo = ServiceInfo
2930

3031

3132
class ServiceRegistry:
@@ -79,7 +80,7 @@ def async_get_infos_server(self, server: str) -> list[ServiceInfo]:
7980
"""Return all ServiceInfo matching server."""
8081
return self._async_get_by_index(self.servers, server)
8182

82-
def _async_get_by_index(self, records: dict[str, list], key: _str) -> list[ServiceInfo]:
83+
def _async_get_by_index(self, records: dict[_str, list], key: _str) -> list[_ServiceInfo]:
8384
"""Return all ServiceInfo matching the index."""
8485
record_list = records.get(key)
8586
if record_list is None:
@@ -98,7 +99,7 @@ def _add(self, info: ServiceInfo) -> None:
9899
self.servers.setdefault(info.server_key, []).append(info.key)
99100
self.has_entries = True
100101

101-
def _remove(self, infos: list[ServiceInfo]) -> None:
102+
def _remove(self, infos: list[_ServiceInfo]) -> None:
102103
"""Remove a services under the lock."""
103104
for info in infos:
104105
old_service_info = self._services.get(info.key)

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL