Skip to content

Commit aaec7c2

Browse files
chore: add cython linter (#1416)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d9be715 commit aaec7c2

7 files changed

Lines changed: 32 additions & 44 deletions

File tree

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,8 @@ repos:
5757
hooks:
5858
- id: mypy
5959
additional_dependencies: []
60+
- repo: https://github.com/MarcoGorelli/cython-lint
61+
rev: v0.16.2
62+
hooks:
63+
- id: cython-lint
64+
- id: double-quote-cython-strings

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,7 @@ build-backend = "poetry.core.masonry.api"
193193

194194
[tool.codespell]
195195
ignore-words-list = ["additionals", "HASS"]
196+
197+
[tool.cython-lint]
198+
max-line-length = 88
199+
ignore = ['E501'] # too many to fix right now

src/zeroconf/_cache.pxd

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ cdef unsigned int _TYPE_PTR
2020
cdef cython.uint _ONE_SECOND
2121
cdef unsigned int _MIN_SCHEDULED_RECORD_EXPIRATION
2222

23-
@cython.locals(
24-
record_cache=dict,
25-
)
23+
24+
@cython.locals(record_cache=dict)
2625
cdef _remove_key(cython.dict cache, object key, DNSRecord record)
2726

2827

@@ -37,36 +36,23 @@ cdef class DNSCache:
3736

3837
cpdef void async_remove_records(self, object entries)
3938

40-
@cython.locals(
41-
store=cython.dict,
42-
)
39+
@cython.locals(store=cython.dict)
4340
cpdef DNSRecord async_get_unique(self, DNSRecord entry)
4441

45-
@cython.locals(
46-
record=DNSRecord,
47-
)
42+
@cython.locals(record=DNSRecord)
4843
cpdef list async_expire(self, double now)
4944

50-
@cython.locals(
51-
records=cython.dict,
52-
record=DNSRecord,
53-
)
45+
@cython.locals(records=cython.dict, record=DNSRecord)
5446
cpdef list async_all_by_details(self, str name, unsigned int type_, unsigned int class_)
5547

5648
cpdef list async_entries_with_name(self, str name)
5749

5850
cpdef list async_entries_with_server(self, str name)
5951

60-
@cython.locals(
61-
cached_entry=DNSRecord,
62-
records=dict
63-
)
52+
@cython.locals(cached_entry=DNSRecord, records=dict)
6453
cpdef DNSRecord get_by_details(self, str name, unsigned int type_, unsigned int class_)
6554

66-
@cython.locals(
67-
records=cython.dict,
68-
entry=DNSRecord,
69-
)
55+
@cython.locals(records=cython.dict, entry=DNSRecord)
7056
cpdef cython.list get_all_by_details(self, str name, unsigned int type_, unsigned int class_)
7157

7258
@cython.locals(
@@ -76,31 +62,19 @@ cdef class DNSCache:
7662
)
7763
cdef bint _async_add(self, DNSRecord record)
7864

79-
@cython.locals(
80-
service_record=DNSService
81-
)
65+
@cython.locals(service_record=DNSService)
8266
cdef void _async_remove(self, DNSRecord record)
8367

84-
@cython.locals(
85-
record=DNSRecord,
86-
created_double=double,
87-
)
68+
@cython.locals(record=DNSRecord, created_double=double)
8869
cpdef void async_mark_unique_records_older_than_1s_to_expire(self, cython.set unique_types, object answers, double now)
8970

90-
@cython.locals(
91-
entries=dict
92-
)
71+
@cython.locals(entries=dict)
9372
cpdef list entries_with_name(self, str name)
9473

95-
@cython.locals(
96-
entries=dict
97-
)
74+
@cython.locals(entries=dict)
9875
cpdef list entries_with_server(self, str server)
9976

100-
@cython.locals(
101-
record=DNSRecord,
102-
now=double
103-
)
77+
@cython.locals(record=DNSRecord, now=double)
10478
cpdef current_entry_with_name_and_alias(self, str name, str alias)
10579

10680
cpdef void _async_set_created_ttl(

src/zeroconf/_handlers/answers.pxd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ cdef class AnswerGroup:
2020
cdef public cython.dict answers
2121

2222

23-
24-
2523
cdef object _FLAGS_QR_RESPONSE_AA
2624
cdef object NAME_GETTER
2725

@@ -31,5 +29,6 @@ cpdef DNSOutgoing construct_outgoing_unicast_answers(
3129
cython.dict answers, bint ucast_source, cython.list questions, object id_
3230
)
3331

32+
3433
@cython.locals(answer=DNSRecord, additionals=cython.set, additional=DNSRecord)
3534
cdef void _add_answers_additionals(DNSOutgoing out, cython.dict answers)

src/zeroconf/_listener.pxd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ cdef cython.uint _MAX_MSG_ABSOLUTE
1616
cdef cython.uint _DUPLICATE_PACKET_SUPPRESSION_INTERVAL
1717

1818

19-
2019
cdef class AsyncListener:
2120

2221
cdef public object zc

src/zeroconf/_services/browser.pxd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ cdef class _DNSPointerOutgoingBucket:
4444

4545
cpdef add(self, cython.uint max_compressed_size, DNSQuestion question, cython.set answers)
4646

47+
4748
@cython.locals(cache=DNSCache, question_history=QuestionHistory, record=DNSRecord, qu_question=bint)
4849
cpdef list generate_service_query(
4950
object zc,
@@ -53,9 +54,11 @@ cpdef list generate_service_query(
5354
object question_type
5455
)
5556

57+
5658
@cython.locals(answer=DNSPointer, query_buckets=list, question=DNSQuestion, max_compressed_size=cython.uint, max_bucket_size=cython.uint, query_bucket=_DNSPointerOutgoingBucket)
5759
cdef list _group_ptr_queries_with_known_answers(double now_millis, bint multicast, cython.dict question_with_known_answers)
5860

61+
5962
cdef class QueryScheduler:
6063

6164
cdef object _zc
@@ -83,7 +86,7 @@ cdef class QueryScheduler:
8386
@cython.locals(current=_ScheduledPTRQuery, expire_time=double)
8487
cpdef void reschedule_ptr_first_refresh(self, DNSPointer pointer)
8588

86-
@cython.locals(ttl_millis='unsigned int', additional_wait=double, next_query_time=double)
89+
@cython.locals(ttl_millis="unsigned int", additional_wait=double, next_query_time=double)
8790
cpdef void schedule_rescue_query(self, _ScheduledPTRQuery query, double now_millis, float additional_percentage)
8891

8992
cpdef void _process_startup_queries(self)
@@ -93,6 +96,7 @@ cdef class QueryScheduler:
9396

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

99+
96100
cdef class _ServiceBrowserBase(RecordUpdateListener):
97101

98102
cdef public cython.set types

src/zeroconf/_utils/ipaddress.pxd

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
cdef bint TYPE_CHECKING
2-
31
from .._dns cimport DNSAddress
42

3+
cdef bint TYPE_CHECKING
4+
55

66
cpdef get_ip_address_object_from_record(DNSAddress record)
77

8+
89
@cython.locals(address_str=str)
910
cpdef str_without_scope_id(object addr)
1011

12+
1113
cpdef ip_bytes_and_scope_to_address(object addr, object scope_id)
1214

15+
1316
cdef object cached_ip_addresses_wrapper

0 commit comments

Comments
 (0)