Fix typing issues

This commit is contained in:
Jake Howard 2023-11-29 14:35:07 +00:00
parent 34dcf63a93
commit 981d0ada4d
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 9 additions and 4 deletions

View file

@ -1,4 +1,8 @@
from typing import Any
from django.http import HttpRequest
from django.utils.feedgenerator import DefaultFeed
from django.utils.xmlutils import SimplerXMLGenerator
class CustomFeed(DefaultFeed):
@ -6,11 +10,11 @@ class CustomFeed(DefaultFeed):
A custom feed generator with additional features.
"""
def __init__(self, request, **kwargs):
def __init__(self, request: HttpRequest, **kwargs: Any) -> None:
super().__init__(**kwargs)
self.request = request
def add_root_elements(self, handler) -> None:
def add_root_elements(self, handler: SimplerXMLGenerator) -> None:
super().add_root_elements(handler)
handler.startElement("image", {})
handler.addQuickElement("url", self.request.build_absolute_uri("favicon.ico"))

View file

@ -89,7 +89,7 @@ class AllPagesFeed(Feed):
return response
def feed_extra_kwargs(self, obj):
def feed_extra_kwargs(self, obj: None) -> dict:
return {**super().feed_extra_kwargs(obj), "request": self.request}
def title(self) -> str:
@ -124,9 +124,10 @@ class AllPagesFeed(Feed):
def item_description(self, item: BasePage) -> str:
return getattr(item, "summary", None) or item.title
def item_categories(self, item: BasePage):
def item_categories(self, item: BasePage) -> Optional[list[str]]:
if tags := getattr(item, "tags", None):
return tags.order_by("slug").values_list("slug", flat=True)
return None
def item_enclosure_url(self, item: BasePage) -> Optional[str]:
if not hasattr(item, "get_meta_image_url"):