From 214209d2a77ed4caa15cd5c216fbd28b1c909ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Tue, 3 Sep 2024 20:59:41 -0700 Subject: [PATCH] fix: type hints should be backward compatible with old Python versions --- miniflux.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/miniflux.py b/miniflux.py index 8e904f9..2410ccb 100644 --- a/miniflux.py +++ b/miniflux.py @@ -21,6 +21,7 @@ # THE SOFTWARE. import json +from typing import List, Optional, Union import requests @@ -104,10 +105,10 @@ class Client: def __init__( self, base_url: str, - username: str | None = None, - password: str | None = None, + username: Optional[str] = None, + password: Optional[str] = None, timeout: float = 30.0, - api_key: str | None = None, + api_key: Optional[str] = None, user_agent: str = DEFAULT_USER_AGENT, ): self._base_url = base_url @@ -115,7 +116,7 @@ def __init__( self._username = username self._password = password self._timeout = timeout - self._auth: tuple | None = ( + self._auth: Optional[tuple] = ( (self._username, self._password) if not api_key else None ) self._headers = {"User-Agent": user_agent} @@ -128,7 +129,7 @@ def _get_endpoint(self, path: str) -> str: return f"{self._base_url}/v{self.API_VERSION}{path}" - def _get_params(self, **kwargs) -> dict | None: + def _get_params(self, **kwargs) -> Optional[dict]: params = {k: v for k, v in kwargs.items() if v} return params if len(params) > 0 else None @@ -248,7 +249,7 @@ def import_feeds(self, opml: str) -> dict: return response.json() self._handle_error_response(response) - def discover(self, website_url: str, **kwargs) -> list[dict]: + def discover(self, website_url: str, **kwargs) -> List[dict]: """ Discover feeds from a website. @@ -274,7 +275,7 @@ def discover(self, website_url: str, **kwargs) -> list[dict]: return response.json() self._handle_error_response(response) - def get_category_feeds(self, category_id: int) -> list[dict]: + def get_category_feeds(self, category_id: int) -> List[dict]: """ Retrieves a list of feeds for a given category. @@ -293,7 +294,7 @@ def get_category_feeds(self, category_id: int) -> list[dict]: return response.json() self._handle_error_response(response) - def get_feeds(self) -> list[dict]: + def get_feeds(self) -> List[dict]: """ Retrieves a list of all feeds. @@ -381,7 +382,7 @@ def get_icon_by_feed_id(self, feed_id: int) -> dict: return self.get_feed_icon(feed_id) def create_feed( - self, feed_url: str, category_id: int | None = None, **kwargs + self, feed_url: str, category_id: Optional[int] = None, **kwargs ) -> int: """ Create a new feed. @@ -608,7 +609,7 @@ def get_entries(self, **kwargs) -> dict: self._handle_error_response(response) def update_entry( - self, entry_id: int, title: str | None = None, content: str | None = None + self, entry_id: int, title: Optional[str] = None, content: Optional[str] = None ) -> dict: """ Update an entry. @@ -742,7 +743,7 @@ def get_enclosure(self, enclosure_id: int) -> dict: self._handle_error_response(response) def update_enclosure( - self, enclosure_id: int, media_progression: int | None = None + self, enclosure_id: int, media_progression: Optional[int] = None ) -> bool: """ Update an enclosure. @@ -768,7 +769,7 @@ def update_enclosure( self._handle_error_response(response) return True - def get_categories(self) -> list[dict]: + def get_categories(self) -> List[dict]: """ Fetch all categories. @@ -910,7 +911,7 @@ def mark_category_entries_as_read(self, category_id: int) -> None: if response.status_code != 204: self._handle_error_response(response) - def get_users(self) -> list[dict]: + def get_users(self) -> List[dict]: """ Fetch all users. @@ -953,7 +954,7 @@ def get_user_by_username(self, username: str) -> dict: """ return self._get_user(username) - def _get_user(self, user_id_or_username: str | int) -> dict: + def _get_user(self, user_id_or_username: Union[str, int]) -> dict: endpoint = self._get_endpoint(f"/users/{user_id_or_username}") response = requests.get( endpoint, headers=self._headers, auth=self._auth, timeout=self._timeout