From 112b341eb6da9c4c6aaa01bc5c97bb7637e93524 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Wed, 29 Dec 2021 15:34:54 +0100 Subject: [PATCH 1/2] Update syndication Feed class --- django-stubs/contrib/syndication/views.pyi | 170 +++++++++++++++++++-- 1 file changed, 157 insertions(+), 13 deletions(-) diff --git a/django-stubs/contrib/syndication/views.pyi b/django-stubs/contrib/syndication/views.pyi index b59b55137..aefb93e1a 100644 --- a/django-stubs/contrib/syndication/views.pyi +++ b/django-stubs/contrib/syndication/views.pyi @@ -1,4 +1,5 @@ -from typing import Any, Dict, List +import datetime +from typing import Any, Dict, Generic, Iterable, List, Optional, Type, TypeVar from django.core.exceptions import ObjectDoesNotExist from django.core.handlers.wsgi import WSGIRequest @@ -11,17 +12,160 @@ def add_domain(domain: str, url: str, secure: bool = ...) -> str: ... class FeedDoesNotExist(ObjectDoesNotExist): ... -class Feed: - feed_type: Any = ... - title_template: Any = ... - description_template: Any = ... +Item = TypeVar("Item") +Object = TypeVar("Object") + +class Feed(Generic[Item, Object]): + feed_type: Type[SyndicationFeed] = ... + title_template: Optional[str] = ... + description_template: Optional[str] = ... + language: Optional[str] = ... def __call__(self, request: WSGIRequest, *args: Any, **kwargs: Any) -> HttpResponse: ... - def item_title(self, item: Model) -> SafeText: ... - def item_description(self, item: Model) -> str: ... - def item_link(self, item: Model) -> str: ... - def item_enclosures(self, item: Model) -> List[Enclosure]: ... - def feed_extra_kwargs(self, obj: None) -> Dict[Any, Any]: ... - def item_extra_kwargs(self, item: Model) -> Dict[Any, Any]: ... - def get_object(self, request: WSGIRequest, *args: Any, **kwargs: Any) -> Any: ... + def get_object(self, request: WSGIRequest, *args: Any, **kwargs: Any) -> Optional[Object]: ... + # One of the following three is required + def title(self, obj: Object) -> str: ... + def title(self) -> str: ... + title: str = ... + + # One of the following three is required + def link(self, obj: Object) -> str: ... + def link(self) -> str: ... + link: str = ... + + # One of the following three is optional + def feed_url(self, obj: Object) -> str: ... + def feed_url(self) -> str: ... + feed_url: str = ... + + # One of the following three is optional + def feed_guid(self, obj: Object) -> str: ... + def feed_guid(self) -> str: ... + feed_guid: str = ... + + # One of the following three is required + def description(self, obj: Object) -> str: ... + def description(self) -> str: ... + description: str = ... + + # One of the following three is optional + def author_name(self, obj: Object) -> str: ... + def author_name(self) -> str: ... + author_name: str = ... + + # One of the following three is optional + def author_email(self, obj: Object) -> str: ... + def author_email(self) -> str: ... + author_email: str = ... + + # One of the following three is optional + def author_link(self, obj: Object) -> str: ... + def author_link(self) -> str: ... + author_link: str = ... + + # One of the following three is optional + def categories(self, obj: Object) -> Iterable[str]: ... + def categories(self) -> Iterable[str]: ... + categories: Iterable[str] = ... + + # One of the following three is optional + def feed_copyright(self, obj: Object) -> str: ... + def feed_copyright(self) -> str: ... + feed_copyright: str = ... + + # One of the following three is optional + def ttl(self, obj: Object) -> int: ... + def ttl(self) -> int: ... + ttl: int = ... + + # One of the following three is required + def items(self, obj: Object) -> Iterable[Item]: ... + def items(self) -> Iterable[Item]: ... + items: Iterable[Item] = ... + + # One of the following three is optional + def item_title(self, item: Item) -> str: ... + def item_title(self) -> str: ... + item_title: str = ... + + # One of the following three is optional + def item_description(self, item: Item) -> str: ... + def item_description(self) -> str: ... + item_description: str = ... + + # One of the following two is optional + def item_link(self, item: Item) -> str: ... + def item_link(self) -> str: ... + # The following is optional + def item_guid(self, item: Item) -> str: ... + # One of the following two is optional + def item_guid_is_permalink(self, item: Item) -> bool: ... + item_guid_is_permalink: bool = ... + + # One of the following three is optional + def item_author_name(self, item: Item) -> str: ... + def item_author_name(self) -> str: ... + item_author_name: str = ... + + # One of the following three is optional + # if this is specified, then item_author_name is required + def item_author_email(self, item: Item) -> str: ... + def item_author_email(self) -> str: ... + item_author_email: str = ... + + # One of the following three is optional + # if this is specified, then item_author_name is required + def item_author_link(self, item: Item) -> str: ... + def item_author_link(self) -> str: ... + item_author_link: str = ... + + # One of the following three is optional + def item_enclosures(self, item: Item) -> Iterable[Enclosure]: ... + def item_enclosures(self) -> Iterable[Enclosure]: ... + item_enclosures: Iterable[Enclosure] = ... + + # One of the following three is required if publishing enclosures + # and not using item_enclosures + def item_enclosure_url(self, item: Item) -> str: ... + def item_enclosure_url(self) -> str: ... + item_enclosure_url: str = ... + + # One of the following three is required if publishing enclosures + # and not using item_enclosures + def item_enclosure_length(self, item: Item) -> int: ... + def item_enclosure_length(self) -> int: ... + item_enclosure_length: int = ... + + # One of the following three is required if publishing enclosures + # and not using item_enclosures + def item_enclosure_mime_type(self, item: Item) -> str: ... + def item_enclosure_mime_type(self) -> str: ... + item_enclosure_mime_type: str = ... + + # One of the following three is optional + def item_pubdate(self, item: Item) -> datetime.datetime: ... + def item_pubdate(self) -> datetime.datetime: ... + item_pubdate: datetime.datetime = ... + + # One of the following three is optional + def item_updateddate(self, item: Item) -> datetime.datetime: ... + def item_updateddate(self) -> datetime.datetime: ... + item_updateddate: datetime.datetime = ... + + # One of the following three is optional + def item_categories(self, item: Item) -> Iterable[str]: ... + def item_categories(self) -> Iterable[str]: ... + item_categories: Iterable[str] = ... + + # One of the following three is optional + def item_copyright(self, item: Item) -> str: ... + def item_copyright(self) -> str: ... + item_copyright: str = ... + + # One of the following three is optional + def item_comments(self, item: Item) -> str: ... + def item_comments(self) -> str: ... + item_comments: str = ... + def feed_extra_kwargs(self, obj: Object) -> Dict[Any, Any]: ... + def item_extra_kwargs(self, item: Item) -> Dict[Any, Any]: ... def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: ... - def get_feed(self, obj: None, request: WSGIRequest) -> SyndicationFeed: ... + def get_feed(self, obj: Object, request: WSGIRequest) -> SyndicationFeed: ... From 7656d0b8717af605981a00f630e14b3a3c2b9379 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Thu, 30 Dec 2021 09:27:01 +0100 Subject: [PATCH 2/2] Fix typing --- django-stubs/contrib/syndication/views.pyi | 190 ++++----------------- 1 file changed, 37 insertions(+), 153 deletions(-) diff --git a/django-stubs/contrib/syndication/views.pyi b/django-stubs/contrib/syndication/views.pyi index aefb93e1a..ca805cd23 100644 --- a/django-stubs/contrib/syndication/views.pyi +++ b/django-stubs/contrib/syndication/views.pyi @@ -1,171 +1,55 @@ import datetime -from typing import Any, Dict, Generic, Iterable, List, Optional, Type, TypeVar +from typing import Any, Callable, Dict, Generic, Iterable, Optional, Type, TypeVar, Union from django.core.exceptions import ObjectDoesNotExist from django.core.handlers.wsgi import WSGIRequest -from django.db.models.base import Model from django.http.response import HttpResponse from django.utils.feedgenerator import Enclosure, SyndicationFeed -from django.utils.safestring import SafeText def add_domain(domain: str, url: str, secure: bool = ...) -> str: ... class FeedDoesNotExist(ObjectDoesNotExist): ... -Item = TypeVar("Item") -Object = TypeVar("Object") +_Item = TypeVar("_Item") +_Object = TypeVar("_Object") -class Feed(Generic[Item, Object]): +class Feed(Generic[_Item, _Object]): feed_type: Type[SyndicationFeed] = ... title_template: Optional[str] = ... description_template: Optional[str] = ... language: Optional[str] = ... + title: Any = ... + link: Any = ... + feed_url: Any = ... + feed_guid: Any = ... + description: Any = ... + author_name: Any = ... + author_email: Any = ... + author_link: Any = ... + categories: Any = ... + feed_copyright: Any = ... + ttl: Any = ... + items: Any = ... + item_title: Any = ... + item_description: Any = ... + item_link: Any = ... + item_guid: Any = ... + item_guid_is_permalink: Any = ... + item_author_name: Any = ... + item_author_email: Any = ... + item_author_link: Any = ... + item_enclosures: Any = ... + item_enclosure_url: Any = ... + item_enclosure_length: Any = ... + item_enclosure_mime_type: Any = ... + item_pubdate: Any = ... + item_updateddate: Any = ... + item_categories: Any = ... + item_copyright: Any = ... + item_comments: Any = ... def __call__(self, request: WSGIRequest, *args: Any, **kwargs: Any) -> HttpResponse: ... - def get_object(self, request: WSGIRequest, *args: Any, **kwargs: Any) -> Optional[Object]: ... - # One of the following three is required - def title(self, obj: Object) -> str: ... - def title(self) -> str: ... - title: str = ... - - # One of the following three is required - def link(self, obj: Object) -> str: ... - def link(self) -> str: ... - link: str = ... - - # One of the following three is optional - def feed_url(self, obj: Object) -> str: ... - def feed_url(self) -> str: ... - feed_url: str = ... - - # One of the following three is optional - def feed_guid(self, obj: Object) -> str: ... - def feed_guid(self) -> str: ... - feed_guid: str = ... - - # One of the following three is required - def description(self, obj: Object) -> str: ... - def description(self) -> str: ... - description: str = ... - - # One of the following three is optional - def author_name(self, obj: Object) -> str: ... - def author_name(self) -> str: ... - author_name: str = ... - - # One of the following three is optional - def author_email(self, obj: Object) -> str: ... - def author_email(self) -> str: ... - author_email: str = ... - - # One of the following three is optional - def author_link(self, obj: Object) -> str: ... - def author_link(self) -> str: ... - author_link: str = ... - - # One of the following three is optional - def categories(self, obj: Object) -> Iterable[str]: ... - def categories(self) -> Iterable[str]: ... - categories: Iterable[str] = ... - - # One of the following three is optional - def feed_copyright(self, obj: Object) -> str: ... - def feed_copyright(self) -> str: ... - feed_copyright: str = ... - - # One of the following three is optional - def ttl(self, obj: Object) -> int: ... - def ttl(self) -> int: ... - ttl: int = ... - - # One of the following three is required - def items(self, obj: Object) -> Iterable[Item]: ... - def items(self) -> Iterable[Item]: ... - items: Iterable[Item] = ... - - # One of the following three is optional - def item_title(self, item: Item) -> str: ... - def item_title(self) -> str: ... - item_title: str = ... - - # One of the following three is optional - def item_description(self, item: Item) -> str: ... - def item_description(self) -> str: ... - item_description: str = ... - - # One of the following two is optional - def item_link(self, item: Item) -> str: ... - def item_link(self) -> str: ... - # The following is optional - def item_guid(self, item: Item) -> str: ... - # One of the following two is optional - def item_guid_is_permalink(self, item: Item) -> bool: ... - item_guid_is_permalink: bool = ... - - # One of the following three is optional - def item_author_name(self, item: Item) -> str: ... - def item_author_name(self) -> str: ... - item_author_name: str = ... - - # One of the following three is optional - # if this is specified, then item_author_name is required - def item_author_email(self, item: Item) -> str: ... - def item_author_email(self) -> str: ... - item_author_email: str = ... - - # One of the following three is optional - # if this is specified, then item_author_name is required - def item_author_link(self, item: Item) -> str: ... - def item_author_link(self) -> str: ... - item_author_link: str = ... - - # One of the following three is optional - def item_enclosures(self, item: Item) -> Iterable[Enclosure]: ... - def item_enclosures(self) -> Iterable[Enclosure]: ... - item_enclosures: Iterable[Enclosure] = ... - - # One of the following three is required if publishing enclosures - # and not using item_enclosures - def item_enclosure_url(self, item: Item) -> str: ... - def item_enclosure_url(self) -> str: ... - item_enclosure_url: str = ... - - # One of the following three is required if publishing enclosures - # and not using item_enclosures - def item_enclosure_length(self, item: Item) -> int: ... - def item_enclosure_length(self) -> int: ... - item_enclosure_length: int = ... - - # One of the following three is required if publishing enclosures - # and not using item_enclosures - def item_enclosure_mime_type(self, item: Item) -> str: ... - def item_enclosure_mime_type(self) -> str: ... - item_enclosure_mime_type: str = ... - - # One of the following three is optional - def item_pubdate(self, item: Item) -> datetime.datetime: ... - def item_pubdate(self) -> datetime.datetime: ... - item_pubdate: datetime.datetime = ... - - # One of the following three is optional - def item_updateddate(self, item: Item) -> datetime.datetime: ... - def item_updateddate(self) -> datetime.datetime: ... - item_updateddate: datetime.datetime = ... - - # One of the following three is optional - def item_categories(self, item: Item) -> Iterable[str]: ... - def item_categories(self) -> Iterable[str]: ... - item_categories: Iterable[str] = ... - - # One of the following three is optional - def item_copyright(self, item: Item) -> str: ... - def item_copyright(self) -> str: ... - item_copyright: str = ... - - # One of the following three is optional - def item_comments(self, item: Item) -> str: ... - def item_comments(self) -> str: ... - item_comments: str = ... - def feed_extra_kwargs(self, obj: Object) -> Dict[Any, Any]: ... - def item_extra_kwargs(self, item: Item) -> Dict[Any, Any]: ... + def get_object(self, request: WSGIRequest, *args: Any, **kwargs: Any) -> Optional[_Object]: ... + def feed_extra_kwargs(self, obj: _Object) -> Dict[Any, Any]: ... + def item_extra_kwargs(self, item: _Item) -> Dict[Any, Any]: ... def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: ... - def get_feed(self, obj: Object, request: WSGIRequest) -> SyndicationFeed: ... + def get_feed(self, obj: _Object, request: WSGIRequest) -> SyndicationFeed: ...