Update Ruff and fix its errors

This commit is contained in:
Joakim Hellsén 2026-07-21 04:12:13 +02:00
commit 1424978854
Signed by: Joakim Hellsén
SSH key fingerprint: SHA256:/9h/CsExpFp+PRhsfA0xznFx2CGfTT5R/kpuFfUgEQk
39 changed files with 183 additions and 175 deletions

View file

@ -8,11 +8,11 @@ from django.db.models import Count
logger = logging.getLogger("ttvdrops.signals")
def _dispatch(task_fn: Any, pk: int) -> None: # noqa: ANN401
def _dispatch(task_fn: Any, pk: int) -> None: # ruff:ignore[any-type]
"""Dispatch a Celery task, logging rather than raising when the broker is unavailable."""
try:
task_fn.delay(pk)
except Exception: # noqa: BLE001
except Exception: # ruff:ignore[blind-except]
logger.debug(
"Could not dispatch %s(%d) — broker may be unavailable.",
task_fn.name,
@ -20,49 +20,57 @@ def _dispatch(task_fn: Any, pk: int) -> None: # noqa: ANN401
)
def on_game_saved(sender: Any, instance: Any, created: bool, **kwargs: Any) -> None: # noqa: ANN401, FBT001
def on_game_saved(sender: Any, instance: Any, created: bool, **kwargs: Any) -> None: # ruff:ignore[any-type, boolean-type-hint-positional-argument]
"""Dispatch a box-art download task when a new Game is created."""
if created:
from twitch.tasks import download_game_image # noqa: PLC0415
from twitch.tasks import ( # ruff:ignore[import-outside-top-level]
download_game_image,
)
_dispatch(download_game_image, instance.pk)
def on_drop_campaign_saved(
sender: Any, # noqa: ANN401
instance: Any, # noqa: ANN401
created: bool, # noqa: FBT001
**kwargs: Any, # noqa: ANN401
sender: Any, # ruff:ignore[any-type]
instance: Any, # ruff:ignore[any-type]
created: bool, # ruff:ignore[boolean-type-hint-positional-argument]
**kwargs: Any, # ruff:ignore[any-type]
) -> None:
"""Dispatch an image download task when a new DropCampaign is created."""
if created:
from twitch.tasks import download_campaign_image # noqa: PLC0415
from twitch.tasks import ( # ruff:ignore[import-outside-top-level]
download_campaign_image,
)
_dispatch(download_campaign_image, instance.pk)
def on_drop_benefit_saved(
sender: Any, # noqa: ANN401
instance: Any, # noqa: ANN401
created: bool, # noqa: FBT001
**kwargs: Any, # noqa: ANN401
sender: Any, # ruff:ignore[any-type]
instance: Any, # ruff:ignore[any-type]
created: bool, # ruff:ignore[boolean-type-hint-positional-argument]
**kwargs: Any, # ruff:ignore[any-type]
) -> None:
"""Dispatch an image download task when a new DropBenefit is created."""
if created:
from twitch.tasks import download_benefit_image # noqa: PLC0415
from twitch.tasks import ( # ruff:ignore[import-outside-top-level]
download_benefit_image,
)
_dispatch(download_benefit_image, instance.pk)
def on_reward_campaign_saved(
sender: Any, # noqa: ANN401
instance: Any, # noqa: ANN401
created: bool, # noqa: FBT001
**kwargs: Any, # noqa: ANN401
sender: Any, # ruff:ignore[any-type]
instance: Any, # ruff:ignore[any-type]
created: bool, # ruff:ignore[boolean-type-hint-positional-argument]
**kwargs: Any, # ruff:ignore[any-type]
) -> None:
"""Dispatch an image download task when a new RewardCampaign is created."""
if created:
from twitch.tasks import download_reward_campaign_image # noqa: PLC0415
from twitch.tasks import ( # ruff:ignore[import-outside-top-level]
download_reward_campaign_image,
)
_dispatch(download_reward_campaign_image, instance.pk)
@ -72,8 +80,8 @@ def _refresh_allowed_campaign_counts(channel_ids: set[int]) -> None:
if not channel_ids:
return
from twitch.models import Channel # noqa: PLC0415
from twitch.models import DropCampaign # noqa: PLC0415
from twitch.models import Channel # ruff:ignore[import-outside-top-level]
from twitch.models import DropCampaign # ruff:ignore[import-outside-top-level]
through_model: type[Channel] = DropCampaign.allow_channels.through
counts_by_channel: dict[int, int] = {
@ -96,19 +104,19 @@ def _refresh_allowed_campaign_counts(channel_ids: set[int]) -> None:
Channel.objects.bulk_update(channels, ["allowed_campaign_count"])
def on_drop_campaign_allow_channels_changed( # noqa: PLR0913, PLR0917
sender: Any, # noqa: ANN401
instance: Any, # noqa: ANN401
def on_drop_campaign_allow_channels_changed( # ruff:ignore[too-many-arguments, too-many-positional-arguments]
sender: Any, # ruff:ignore[any-type]
instance: Any, # ruff:ignore[any-type]
action: str,
reverse: bool, # noqa: FBT001
model: Any, # noqa: ANN401
reverse: bool, # ruff:ignore[boolean-type-hint-positional-argument]
model: Any, # ruff:ignore[any-type]
pk_set: set[int] | None,
**kwargs: Any, # noqa: ANN401
**kwargs: Any, # ruff:ignore[any-type]
) -> None:
"""Keep Channel.allowed_campaign_count in sync for allow_channels M2M changes."""
if action == "pre_clear" and not reverse:
# post_clear does not expose removed channel IDs; snapshot before clearing.
instance._pre_clear_channel_ids = set( # pyright: ignore[reportAttributeAccessIssue] # noqa: SLF001
instance._pre_clear_channel_ids = set( # pyright: ignore[reportAttributeAccessIssue] # ruff:ignore[private-member-access]
instance.allow_channels.values_list("pk", flat=True), # pyright: ignore[reportAttributeAccessIssue]
)
return