style: say which lint rules this repo keeps, then keep them

`[tool.ruff]` set a line length and a target version and nothing else, so which
rules ran depended on the installed ruff's defaults — fine while nobody ran it,
not fine for a CI job that can turn a push red because a tool changed its mind.

The set is named explicitly (E, F, I, UP, SIM, B, RUF) with three ignores that
are each a real decision rather than a shrug: B008, because FastAPI's whole
dependency idiom is a call in a default argument; E501, because wrapping prose
is a formatter's business; and RUF001, because the reports and the bot speak
Russian and "ambiguous character" is the wrong complaint about a string the
user is meant to read.

The 73 findings that remained are fixed — mostly `datetime.timezone.utc` →
`datetime.UTC`, `typing.Callable` → `collections.abc.Callable`, import order,
and unused `noqa` markers — plus seven by hand: `contextlib.suppress` for two
try/except/pass pairs, unpacking instead of list concatenation, one negated
return.

`ruff format` is deliberately *not* adopted: it would reformat 51 files, and
some of the layout here is hand-set (the comment tables, the DNS wire-format
structs) in ways a formatter flattens.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
timka123andClaude Opus 5 committed 2026-10-22 17:28:57 +03:00
1 parent 5facf41f10
commit ec7eedbc66
28 files changed
+84 -68

No files matched your search

+5 -6
View File
@@ -12,6 +12,7 @@ hostname, so the worst a compromised client can do is block a site.
from __future__ import annotations
import contextlib
import logging
import os
import re
@@ -35,7 +36,7 @@ def valid_hostname(name: str) -> bool:
def current_block() -> list[str]:
"""The hostnames currently inside our managed region of `/etc/hosts`."""
try:
with open(HOSTS_PATH, "r", encoding="utf-8") as handle:
with open(HOSTS_PATH, encoding="utf-8") as handle:
lines = handle.read().splitlines()
except OSError:
return []
@@ -124,12 +125,10 @@ class HostsBlocker:
list_path = handle.name
os.chmod(list_path, 0o644) # the helper reads it as root from /tmp
try:
return self._run(runner + ["apply", "--ip", redirect_ip, "--file", list_path])
return self._run([*runner, "apply", "--ip", redirect_ip, "--file", list_path])
finally:
try:
with contextlib.suppress(OSError):
os.unlink(list_path)
except OSError:
pass
def clear(self) -> bool:
"""Remove the managed region. Safe to call when it is not there."""
@@ -138,7 +137,7 @@ class HostsBlocker:
runner = self._runner()
if runner is None:
return False
return self._run(runner + ["clear"])
return self._run([*runner, "clear"])
def _run(self, command: list[str]) -> bool:
try: