Skip to content

Commit

Permalink
fix: type hints should be backward compatible with old Python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed Sep 4, 2024
1 parent fe8eee0 commit 214209d
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions miniflux.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# THE SOFTWARE.

import json
from typing import List, Optional, Union

import requests

Expand Down Expand Up @@ -104,18 +105,18 @@ 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
self._api_key = api_key
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}
Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 214209d

Please sign in to comment.