lint: clear what ruff 0.17.2 and sickdays' pylint hook flag

- sickdays: normalise_keep raises TypeError (not ValueError) for a bare
  string -- ruff 0.17.2 TRY004; it is a caller type error, the CLI always
  passes a list.
- sickdays: remove_sick_day and set_kept_lockers share require_sick(), which
  clears pylint R0801 (duplicate-code, 9.99/10 under --fail-under=10).
- repo_contract/web.py: tomllib sorts as stdlib under ruff 0.17.x (I001).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NBScELfMUiieK9ManFbS3Y
This commit is contained in:
Krzysztof Rudnicki 2026-10-22 21:42:16 +02:00
parent 9980407095
commit cca7dd680f
5 changed files with 21 additions and 15 deletions

View File

@ -23,11 +23,10 @@ from __future__ import annotations
import json import json
import re import re
import tomllib
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path, PurePosixPath from pathlib import Path, PurePosixPath
import tomllib
from repo_contract.infer import _pm from repo_contract.infer import _pm
from repo_contract.sources import package_scripts, read_text from repo_contract.sources import package_scripts, read_text

View File

@ -32,7 +32,7 @@ if TYPE_CHECKING:
from datetime import date from datetime import date
from pathlib import Path from pathlib import Path
from crdt_sync import Log from crdt_sync import Log, Record
from sickdays._conflict import FreePredicate from sickdays._conflict import FreePredicate
@ -47,6 +47,19 @@ def actor_id(paths: Paths | None = None) -> str:
return load_device_identity(resolve_paths(paths).device_id).device_id return load_device_identity(resolve_paths(paths).device_id).device_id
def require_sick(log: Log, day: date) -> Record:
"""The record that makes ``day`` sick in ``log``.
Raises:
NotSickError: ``day`` is not a sick day.
"""
existing = log.get(to_iso(day))
if existing is None or not is_sick_record(existing):
msg = f"{to_iso(day)} is not a sick day"
raise NotSickError(msg)
return existing
def is_sick_day( def is_sick_day(
day: date | None = None, day: date | None = None,
*, *,
@ -125,10 +138,7 @@ def remove_sick_day(
resolved = resolve_paths(paths) resolved = resolve_paths(paths)
refuse_past(day, today(now), "removed") refuse_past(day, today(now), "removed")
log = read_pool_strict(resolved.log) log = read_pool_strict(resolved.log)
existing = log.get(to_iso(day)) require_sick(log, day)
if existing is None or not is_sick_record(existing):
msg = f"{to_iso(day)} is not a sick day"
raise NotSickError(msg)
entry = SickDay(day=day, is_sick=False, actor=actor_id(resolved)) entry = SickDay(day=day, is_sick=False, actor=actor_id(resolved))
write_entry(log, entry, resolved) write_entry(log, entry, resolved)
record_event("remove", day, actor=entry.actor, paths=resolved) record_event("remove", day, actor=entry.actor, paths=resolved)

View File

@ -58,11 +58,12 @@ def normalise_keep(keep: Iterable[str]) -> frozenset[str]:
A bare string is refused rather than iterated character by character. A bare string is refused rather than iterated character by character.
Raises: Raises:
TypeError: ``keep`` is a bare string, not a collection of ids.
ValueError: An id is not one of :data:`sickdays.LOCKERS`. ValueError: An id is not one of :data:`sickdays.LOCKERS`.
""" """
if isinstance(keep, str): if isinstance(keep, str):
msg = f"keep must be a collection of locker ids, not the string {keep!r}" msg = f"keep must be a collection of locker ids, not the string {keep!r}"
raise ValueError(msg) raise TypeError(msg)
return frozenset(validate_locker(locker) for locker in keep) return frozenset(validate_locker(locker) for locker in keep)

View File

@ -13,10 +13,9 @@ from __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from sickdays._api import actor_id, load from sickdays._api import actor_id, load, require_sick
from sickdays._audit import record_event from sickdays._audit import record_event
from sickdays._day import to_iso, today from sickdays._day import to_iso, today
from sickdays._errors import NotSickError
from sickdays._keep import normalise_keep, read_keep, validate_locker from sickdays._keep import normalise_keep, read_keep, validate_locker
from sickdays._model import SickDay, is_sick_record from sickdays._model import SickDay, is_sick_record
from sickdays._paths import resolve_paths from sickdays._paths import resolve_paths
@ -98,10 +97,7 @@ def set_kept_lockers(
resolved = resolve_paths(paths) resolved = resolve_paths(paths)
refuse_past(day, today(now), "changed") refuse_past(day, today(now), "changed")
log = read_pool_strict(resolved.log) log = read_pool_strict(resolved.log)
existing = log.get(to_iso(day)) existing = require_sick(log, day)
if existing is None or not is_sick_record(existing):
msg = f"{to_iso(day)} is not a sick day"
raise NotSickError(msg)
actor = actor_id(resolved) actor = actor_id(resolved)
write_keep(log, existing, kept, actor=actor, resolved=resolved) write_keep(log, existing, kept, actor=actor, resolved=resolved)
record_event("keep", day, actor=actor, keep=kept, paths=resolved) record_event("keep", day, actor=actor, keep=kept, paths=resolved)

View File

@ -88,7 +88,7 @@ def test_validate_locker_names_the_choices() -> None:
def test_normalise_deduplicates_and_refuses_junk() -> None: def test_normalise_deduplicates_and_refuses_junk() -> None:
assert normalise_keep(["diet", "diet", "book"]) == {"book", "diet"} assert normalise_keep(["diet", "diet", "book"]) == {"book", "diet"}
assert normalise_keep(()) == frozenset() assert normalise_keep(()) == frozenset()
with pytest.raises(ValueError, match="not the string"): with pytest.raises(TypeError, match="not the string"):
normalise_keep("diet") normalise_keep("diet")
with pytest.raises(ValueError, match="unknown locker"): with pytest.raises(ValueError, match="unknown locker"):
normalise_keep(["diet", "nope"]) normalise_keep(["diet", "nope"])