From 981d0ada4dec45183a7201e64f203f08b872441e Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 29 Nov 2023 14:35:07 +0000 Subject: [PATCH] Fix typing issues --- website/common/feed_generators.py | 8 ++++++-- website/common/views.py | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/website/common/feed_generators.py b/website/common/feed_generators.py index 80bfe4f..6a64df1 100644 --- a/website/common/feed_generators.py +++ b/website/common/feed_generators.py @@ -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")) diff --git a/website/common/views.py b/website/common/views.py index e9a5079..e738507 100644 --- a/website/common/views.py +++ b/website/common/views.py @@ -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"):