diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8551ee8b..c7603360 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 diff --git a/pyproject.toml b/pyproject.toml index 450c8aa7..c77333ee 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 diff --git a/src/zeroconf/_cache.pxd b/src/zeroconf/_cache.pxd index 7f78a736..a39ed756 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( diff --git a/src/zeroconf/_handlers/answers.pxd b/src/zeroconf/_handlers/answers.pxd index 25b3c1a1..759905f2 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) diff --git a/src/zeroconf/_listener.pxd b/src/zeroconf/_listener.pxd index 96f52be0..20084b47 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 diff --git a/src/zeroconf/_services/browser.pxd b/src/zeroconf/_services/browser.pxd index 4649291c..1ea99c82 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 @@ -83,7 +86,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) @@ -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 diff --git a/src/zeroconf/_utils/ipaddress.pxd b/src/zeroconf/_utils/ipaddress.pxd index 01d38164..78bbdfbd 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