Skip to content

Commit 0ca624d

Browse files
chore: enable some more ruff rules (#1522)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent cf44289 commit 0ca624d

File tree

11 files changed

+91
-19
lines changed

11 files changed

+91
-19
lines changed

build_ext.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,3 @@ def build(setup_kwargs: Any) -> None:
5454
except Exception:
5555
if os.environ.get("REQUIRE_CYTHON"):
5656
raise
57-
pass

pyproject.toml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,24 @@ line-length = 110
9393
ignore = [
9494
"S101", # use of assert
9595
"S104", # S104 Possible binding to all interfaces
96+
"PLR0912", # too many to fix right now
97+
"TC001", # too many to fix right now
98+
"TID252", # skip
99+
"PLR0913", # too late to make changes here
100+
"PLR0911", # would be breaking change
101+
"TRY003", # too many to fix
102+
"SLF001", # design choice
103+
"TC003", # too many to fix
104+
"PLR2004" , # too many to fix
105+
"PGH004", # too many to fix
106+
"PGH003", # too many to fix
107+
"SIM110", # this is slower
108+
"FURB136", # this is slower for Cython
109+
"PYI034", # enable when we drop Py3.10
110+
"PYI032", # breaks Cython
111+
"PYI041", # breaks Cython
112+
"FURB188", # usually slower
113+
"PERF401", # Cython: closures inside cpdef functions not yet supported
96114
]
97115
select = [
98116
"B", # flake8-bugbear
@@ -104,8 +122,67 @@ select = [
104122
"UP", # pyupgrade
105123
"I", # isort
106124
"RUF", # ruff specific
125+
"FLY", # flynt
126+
"FURB", # refurb
127+
"G", # flake8-logging-format ,
128+
"PERF", # Perflint
129+
"PGH", # pygrep-hooks
130+
"PIE", # flake8-pie
131+
"PL", # pylint
132+
"PT", # flake8-pytest-style
133+
"PTH", # flake8-pathlib
134+
"PYI", # flake8-pyi
135+
"RET", # flake8-return
136+
"RSE", # flake8-raise ,
137+
"SIM", # flake8-simplify
138+
"SLF", # flake8-self
139+
"SLOT", # flake8-slots
140+
"T100", # Trace found: {name} used
141+
"T20", # flake8-print
142+
"TC", # flake8-type-checking
143+
"TID", # Tidy imports
144+
"TRY", # tryceratops
107145
]
108146

147+
[tool.ruff.lint.per-file-ignores]
148+
"tests/**/*" = [
149+
"D100",
150+
"D101",
151+
"D102",
152+
"D103",
153+
"D104",
154+
"S101",
155+
"SLF001",
156+
"PLR2004", # too many to fix right now
157+
"PT011", # too many to fix right now
158+
"PT006", # too many to fix right now
159+
"PGH003", # too many to fix right now
160+
"PT007", # too many to fix right now
161+
"PT027", # too many to fix right now
162+
"PLW0603" , # too many to fix right now
163+
"PLR0915", # too many to fix right now
164+
"FLY002", # too many to fix right now
165+
"PT018", # too many to fix right now
166+
"PLR0124", # too many to fix right now
167+
"SIM202" , # too many to fix right now
168+
"PT012" , # too many to fix right now
169+
"TID252", # too many to fix right now
170+
"PLR0913", # skip this one
171+
"SIM102" , # too many to fix right now
172+
"SIM108", # too many to fix right now
173+
"TC003", # too many to fix right now
174+
"TC002", # too many to fix right now
175+
"T201", # too many to fix right now
176+
]
177+
"bench/**/*" = [
178+
"T201", # intended
179+
]
180+
"examples/**/*" = [
181+
"T201", # intended
182+
]
183+
"setup.py" = ["D100"]
184+
"conftest.py" = ["D100"]
185+
"docs/conf.py" = ["D100"]
109186

110187
[tool.pylint.BASIC]
111188
class-const-naming-style = "any"

src/zeroconf/_history.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ def suppresses(self, question: DNSQuestion, now: _float, known_answers: set[DNSR
6060
return False
6161
# The last question has more known answers than
6262
# we knew so we have to ask
63-
if previous_known_answers - known_answers:
64-
return False
65-
return True
63+
return not previous_known_answers - known_answers
6664

6765
def async_expire(self, now: _float) -> None:
6866
"""Expire the history of old questions."""

src/zeroconf/_protocol/incoming.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def _read_bitmap(self, end: _int) -> list[int]:
398398
bitmap_length = view[offset_plus_one]
399399
bitmap_end = offset_plus_two + bitmap_length
400400
for i, byte in enumerate(self.data[offset_plus_two:bitmap_end]):
401-
for bit in range(0, 8):
401+
for bit in range(8):
402402
if byte & (0x80 >> bit):
403403
rdtypes.append(bit + window * 256 + i * 8)
404404
self.offset += 2 + bitmap_length

src/zeroconf/_protocol/outgoing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def write_name(self, name: str_) -> None:
272272
"""
273273

274274
# split name into each label
275-
if name.endswith("."):
275+
if name and name[-1] == ".":
276276
name = name[:-1]
277277

278278
index = self.names.get(name, 0)

src/zeroconf/_record_update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ def __getitem__(self, index: int) -> DNSRecord | None:
4343
"""Get the new or old record."""
4444
if index == 0:
4545
return self.new
46-
elif index == 1:
46+
if index == 1:
4747
return self.old
4848
raise IndexError(index)

src/zeroconf/_services/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ class ServiceStateChange(enum.Enum):
3838

3939
class ServiceListener:
4040
def add_service(self, zc: Zeroconf, type_: str, name: str) -> None:
41-
raise NotImplementedError()
41+
raise NotImplementedError
4242

4343
def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None:
44-
raise NotImplementedError()
44+
raise NotImplementedError
4545

4646
def update_service(self, zc: Zeroconf, type_: str, name: str) -> None:
47-
raise NotImplementedError()
47+
raise NotImplementedError
4848

4949

5050
class Signal:

src/zeroconf/_services/info.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,13 @@ def _set_properties(self, properties: dict[str | bytes, str | bytes | None]) ->
378378
result = b""
379379
for key, value in properties.items():
380380
if isinstance(key, str):
381-
key = key.encode("utf-8")
381+
key = key.encode("utf-8") # noqa: PLW2901
382382
properties_contain_str = True
383383

384384
record = key
385385
if value is not None:
386386
if not isinstance(value, bytes):
387-
value = str(value).encode("utf-8")
387+
value = str(value).encode("utf-8") # noqa: PLW2901
388388
properties_contain_str = True
389389
record += b"=" + value
390390
list_.append(record)
@@ -524,7 +524,7 @@ def _process_record_threadsafe(self, zc: Zeroconf, record: DNSRecord, now: float
524524
# since by default IPv4Address.__eq__ compares the
525525
# the addresses on version and int which more than
526526
# we need here since we know the version is 4.
527-
elif ip_addr.zc_integer != ipv4_addresses[0].zc_integer:
527+
if ip_addr.zc_integer != ipv4_addresses[0].zc_integer:
528528
ipv4_addresses.remove(ip_addr)
529529
ipv4_addresses.insert(0, ip_addr)
530530

@@ -540,7 +540,7 @@ def _process_record_threadsafe(self, zc: Zeroconf, record: DNSRecord, now: float
540540
# since by default IPv6Address.__eq__ compares the
541541
# the addresses on version and int which more than
542542
# we need here since we know the version is 6.
543-
elif ip_addr.zc_integer != self._ipv6_addresses[0].zc_integer:
543+
if ip_addr.zc_integer != self._ipv6_addresses[0].zc_integer:
544544
ipv6_addresses.remove(ip_addr)
545545
ipv6_addresses.insert(0, ip_addr)
546546

tests/test_handlers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,9 @@ def test_ttl(self):
6767
def get_ttl(record_type):
6868
if expected_ttl is not None:
6969
return expected_ttl
70-
elif record_type in [const._TYPE_A, const._TYPE_SRV, const._TYPE_NSEC]:
70+
if record_type in [const._TYPE_A, const._TYPE_SRV, const._TYPE_NSEC]:
7171
return const._DNS_HOST_TTL
72-
else:
73-
return const._DNS_OTHER_TTL
72+
return const._DNS_OTHER_TTL
7473

7574
def _process_outgoing_packet(out):
7675
"""Sends an outgoing packet."""

tests/test_history.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import zeroconf as r
6-
import zeroconf.const as const
6+
from zeroconf import const
77
from zeroconf._history import QuestionHistory
88

99

0 commit comments

Comments
 (0)