From b664f33bc63c959f1132b957b95365feb84030f4 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 24 Sep 2024 13:09:59 -0500 Subject: [PATCH 1/9] chore: add cython linter --- .pre-commit-config.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 74b047764..05621f41f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -57,3 +57,8 @@ repos: hooks: - id: mypy additional_dependencies: [] + - repo: https://github.com/MarcoGorelli/cython-lint + rev: v0.16.2 + hooks: + - id: cython-lint + - id: double-quote-cython-strings From 0becc6df96a26df448d955459c7f07f0f2faa204 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 18:10:29 +0000 Subject: [PATCH 2/9] chore(pre-commit.ci): auto fixes --- src/zeroconf/_services/browser.pxd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zeroconf/_services/browser.pxd b/src/zeroconf/_services/browser.pxd index 4649291c7..b12ff54f0 100644 --- a/src/zeroconf/_services/browser.pxd +++ b/src/zeroconf/_services/browser.pxd @@ -83,7 +83,7 @@ cdef class QueryScheduler: @cython.locals(current=_ScheduledPTRQuery, expire_time=double) cpdef void reschedule_ptr_first_refresh(self, DNSPointer pointer) - @cython.locals(ttl_millis='unsigned int', additional_wait=double, next_query_time=double) + @cython.locals(ttl_millis="unsigned int", additional_wait=double, next_query_time=double) cpdef void schedule_rescue_query(self, _ScheduledPTRQuery query, double now_millis, float additional_percentage) cpdef void _process_startup_queries(self) From 6f48be5d61555ca6a421b8a8e6532f9fd9be3479 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 24 Sep 2024 13:12:51 -0500 Subject: [PATCH 3/9] chore: add cython linter --- src/zeroconf/_services/browser.pxd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zeroconf/_services/browser.pxd b/src/zeroconf/_services/browser.pxd index 4649291c7..b12ff54f0 100644 --- a/src/zeroconf/_services/browser.pxd +++ b/src/zeroconf/_services/browser.pxd @@ -83,7 +83,7 @@ cdef class QueryScheduler: @cython.locals(current=_ScheduledPTRQuery, expire_time=double) cpdef void reschedule_ptr_first_refresh(self, DNSPointer pointer) - @cython.locals(ttl_millis='unsigned int', additional_wait=double, next_query_time=double) + @cython.locals(ttl_millis="unsigned int", additional_wait=double, next_query_time=double) cpdef void schedule_rescue_query(self, _ScheduledPTRQuery query, double now_millis, float additional_percentage) cpdef void _process_startup_queries(self) From 981da9897980f8cf8c1cf844fd6dd2337436c19b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 16 Jan 2025 13:41:26 -1000 Subject: [PATCH 4/9] chore: add config for cython lint --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 450c8aa7f..c77333eeb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -193,3 +193,7 @@ build-backend = "poetry.core.masonry.api" [tool.codespell] ignore-words-list = ["additionals", "HASS"] + +[tool.cython-lint] +max-line-length = 88 +ignore = ['E501'] # too many to fix right now From 5166a88575f8c3a3785b347ed28d359594ae5f5f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 16 Jan 2025 13:43:34 -1000 Subject: [PATCH 5/9] chore: fix lint issues --- src/zeroconf/_services/browser.pxd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/zeroconf/_services/browser.pxd b/src/zeroconf/_services/browser.pxd index b12ff54f0..1ea99c82d 100644 --- a/src/zeroconf/_services/browser.pxd +++ b/src/zeroconf/_services/browser.pxd @@ -44,6 +44,7 @@ cdef class _DNSPointerOutgoingBucket: cpdef add(self, cython.uint max_compressed_size, DNSQuestion question, cython.set answers) + @cython.locals(cache=DNSCache, question_history=QuestionHistory, record=DNSRecord, qu_question=bint) cpdef list generate_service_query( object zc, @@ -53,9 +54,11 @@ cpdef list generate_service_query( object question_type ) + @cython.locals(answer=DNSPointer, query_buckets=list, question=DNSQuestion, max_compressed_size=cython.uint, max_bucket_size=cython.uint, query_bucket=_DNSPointerOutgoingBucket) cdef list _group_ptr_queries_with_known_answers(double now_millis, bint multicast, cython.dict question_with_known_answers) + cdef class QueryScheduler: cdef object _zc @@ -93,6 +96,7 @@ cdef class QueryScheduler: cpdef void async_send_ready_queries(self, bint first_request, double now_millis, set ready_types) + cdef class _ServiceBrowserBase(RecordUpdateListener): cdef public cython.set types From 8061883bf3c35b2824b11775d296169aa57c0cdb Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 16 Jan 2025 13:44:53 -1000 Subject: [PATCH 6/9] chore: fix lint issues --- src/zeroconf/_cache.pxd | 50 ++++++++++------------------------------- 1 file changed, 12 insertions(+), 38 deletions(-) diff --git a/src/zeroconf/_cache.pxd b/src/zeroconf/_cache.pxd index 7f78a736e..a39ed7562 100644 --- a/src/zeroconf/_cache.pxd +++ b/src/zeroconf/_cache.pxd @@ -20,9 +20,8 @@ cdef unsigned int _TYPE_PTR cdef cython.uint _ONE_SECOND cdef unsigned int _MIN_SCHEDULED_RECORD_EXPIRATION -@cython.locals( - record_cache=dict, -) + +@cython.locals(record_cache=dict) cdef _remove_key(cython.dict cache, object key, DNSRecord record) @@ -37,36 +36,23 @@ cdef class DNSCache: cpdef void async_remove_records(self, object entries) - @cython.locals( - store=cython.dict, - ) + @cython.locals(store=cython.dict) cpdef DNSRecord async_get_unique(self, DNSRecord entry) - @cython.locals( - record=DNSRecord, - ) + @cython.locals(record=DNSRecord) cpdef list async_expire(self, double now) - @cython.locals( - records=cython.dict, - record=DNSRecord, - ) + @cython.locals(records=cython.dict, record=DNSRecord) cpdef list async_all_by_details(self, str name, unsigned int type_, unsigned int class_) cpdef list async_entries_with_name(self, str name) cpdef list async_entries_with_server(self, str name) - @cython.locals( - cached_entry=DNSRecord, - records=dict - ) + @cython.locals(cached_entry=DNSRecord, records=dict) cpdef DNSRecord get_by_details(self, str name, unsigned int type_, unsigned int class_) - @cython.locals( - records=cython.dict, - entry=DNSRecord, - ) + @cython.locals(records=cython.dict, entry=DNSRecord) cpdef cython.list get_all_by_details(self, str name, unsigned int type_, unsigned int class_) @cython.locals( @@ -76,31 +62,19 @@ cdef class DNSCache: ) cdef bint _async_add(self, DNSRecord record) - @cython.locals( - service_record=DNSService - ) + @cython.locals(service_record=DNSService) cdef void _async_remove(self, DNSRecord record) - @cython.locals( - record=DNSRecord, - created_double=double, - ) + @cython.locals(record=DNSRecord, created_double=double) cpdef void async_mark_unique_records_older_than_1s_to_expire(self, cython.set unique_types, object answers, double now) - @cython.locals( - entries=dict - ) + @cython.locals(entries=dict) cpdef list entries_with_name(self, str name) - @cython.locals( - entries=dict - ) + @cython.locals(entries=dict) cpdef list entries_with_server(self, str server) - @cython.locals( - record=DNSRecord, - now=double - ) + @cython.locals(record=DNSRecord, now=double) cpdef current_entry_with_name_and_alias(self, str name, str alias) cpdef void _async_set_created_ttl( From 80972dd545485987dc8dae141eb7ccb66b5596cd Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 16 Jan 2025 13:45:15 -1000 Subject: [PATCH 7/9] chore: fix lint issues --- src/zeroconf/_listener.pxd | 1 - 1 file changed, 1 deletion(-) diff --git a/src/zeroconf/_listener.pxd b/src/zeroconf/_listener.pxd index 96f52be02..20084b47c 100644 --- a/src/zeroconf/_listener.pxd +++ b/src/zeroconf/_listener.pxd @@ -16,7 +16,6 @@ cdef cython.uint _MAX_MSG_ABSOLUTE cdef cython.uint _DUPLICATE_PACKET_SUPPRESSION_INTERVAL - cdef class AsyncListener: cdef public object zc From 6f22f88ec2c0b908e6b7909aed04c077b82038eb Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 16 Jan 2025 13:45:39 -1000 Subject: [PATCH 8/9] chore: fix lint issues --- src/zeroconf/_handlers/answers.pxd | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/zeroconf/_handlers/answers.pxd b/src/zeroconf/_handlers/answers.pxd index 25b3c1a1e..759905f27 100644 --- a/src/zeroconf/_handlers/answers.pxd +++ b/src/zeroconf/_handlers/answers.pxd @@ -20,8 +20,6 @@ cdef class AnswerGroup: cdef public cython.dict answers - - cdef object _FLAGS_QR_RESPONSE_AA cdef object NAME_GETTER @@ -31,5 +29,6 @@ cpdef DNSOutgoing construct_outgoing_unicast_answers( cython.dict answers, bint ucast_source, cython.list questions, object id_ ) + @cython.locals(answer=DNSRecord, additionals=cython.set, additional=DNSRecord) cdef void _add_answers_additionals(DNSOutgoing out, cython.dict answers) From 05a0d478166a2c4cdbc8a135694ea4dfc9622a8c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 16 Jan 2025 13:46:11 -1000 Subject: [PATCH 9/9] chore: fix lint issues --- src/zeroconf/_utils/ipaddress.pxd | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/zeroconf/_utils/ipaddress.pxd b/src/zeroconf/_utils/ipaddress.pxd index 01d381640..78bbdfbdd 100644 --- a/src/zeroconf/_utils/ipaddress.pxd +++ b/src/zeroconf/_utils/ipaddress.pxd @@ -1,13 +1,16 @@ -cdef bint TYPE_CHECKING - from .._dns cimport DNSAddress +cdef bint TYPE_CHECKING + cpdef get_ip_address_object_from_record(DNSAddress record) + @cython.locals(address_str=str) cpdef str_without_scope_id(object addr) + cpdef ip_bytes_and_scope_to_address(object addr, object scope_id) + cdef object cached_ip_addresses_wrapper