fix: add cast to satisfy ty type checker for list covariance

The ty type checker correctly flags that list[str] is not a subtype of list[str | None] due to list invariance. Added explicit cast.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
claude[bot] 2026-02-23 08:42:24 +00:00
parent 16e043883a
commit bf4e38c301

View file

@ -1,6 +1,6 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, cast
import sentry_sdk
from asgiref.sync import sync_to_async
@ -20,7 +20,7 @@ features_api = NinjaAPI(urls_namespace="log_features")
def _positional_list(items: list[str] | None, index: int | None) -> list[str | None] | None:
"""Place a single item at the correct index, padding with None."""
if not items or index is None or len(items) != 1:
return items
return cast("list[str | None] | None", items)
result: list[str | None] = [None] * (index + 1)
result[index] = items[0]
return result