Skip to content

Commit

Permalink
python 3.8 compatible static typing
Browse files Browse the repository at this point in the history
  • Loading branch information
NicKoehler committed Jun 18, 2023
1 parent 9e18a6a commit 2e62002
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [
]
version = "v0.1.0"
readme = "README.md"
requires-python = ">=3.10,<3.11"
requires-python = ">=3.8,<3.11"
license = { file="LICENSE" }
classifiers = [
"Programming Language :: Python :: 3",
Expand Down
6 changes: 4 additions & 2 deletions pythorhead/auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

import requests
from loguru import logger

Expand All @@ -15,8 +17,8 @@ def __call__(cls, *args, **kwargs):


class Authentication(metaclass=Singleton):
token: str | None = None
api_base_url: str | None = None
token: Optional[str] = None
api_base_url: Optional[str] = None

def log_in(self, username_or_email: str, password: str) -> bool:
payload = {
Expand Down
4 changes: 3 additions & 1 deletion pythorhead/lemmy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

import requests
from loguru import logger

Expand All @@ -18,7 +20,7 @@ def __init__(self, api_base_url: str) -> None:
def log_in(self, username_or_email: str, password: str) -> bool:
return Authentication().log_in(username_or_email, password)

def discover_community(self, community_name: str) -> int | None:
def discover_community(self, community_name: str) -> Optional[int]:
if community_name in self._known_communities:
return self._known_communities[community_name]
try:
Expand Down
42 changes: 21 additions & 21 deletions pythorhead/post.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Literal
from typing import Any, Literal, Optional, List

import requests
from loguru import logger
Expand All @@ -14,7 +14,7 @@ def __init__(self):
def get(
self,
post_id: int,
comment_id: int | None = None,
comment_id: Optional[int] = None,
) -> dict:
"""
Get a post.
Expand Down Expand Up @@ -42,14 +42,14 @@ def get(

def list( # noqa: A003
self,
community_id: int | None = None,
community_name: str | None = None,
limit: int | None = None,
page: int | None = None,
saved_only: bool | None = None,
sort: SortType | None = None,
type_: ListingType | None = None,
) -> list[dict]:
community_id: Optional[int] = None,
community_name: Optional[str] = None,
limit: Optional[int] = None,
page: Optional[int] = None,
saved_only: Optional[bool] = None,
sort: Optional[SortType] = None,
type_: Optional[ListingType] = None,
) -> List[dict]:
"""
Get posts, with various filters.
Expand Down Expand Up @@ -95,11 +95,11 @@ def create(
self,
community_id: int,
name: str,
url: str | None = None,
body: str | None = None,
nsfw: bool | None = None,
honeypot: str | None = None,
language_id: int | None = None,
url: Optional[str] = None,
body: Optional[str] = None,
nsfw: Optional[bool] = None,
honeypot: Optional[str] = None,
language_id: Optional[int] = None,
) -> bool:
"""
Create a post
Expand Down Expand Up @@ -161,7 +161,7 @@ def delete(self, post_id: int, deleted: bool) -> bool:
logger.error(f"Error encountered while deleting post: {re.text}")
return re.ok

def remove(self, post_id: int, removed: bool, reason: str | None = None) -> bool:
def remove(self, post_id: int, removed: bool, reason: Optional[str] = None) -> bool:
"""
Moderator remove / restore a post.
Expand Down Expand Up @@ -189,11 +189,11 @@ def remove(self, post_id: int, removed: bool, reason: str | None = None) -> bool
def edit(
self,
post_id: int,
name: str | None = None,
url: str | None = None,
body: str | None = None,
nsfw: bool | None = None,
language_id: int | None = None,
name: Optional[str] = None,
url: Optional[str] = None,
body: Optional[str] = None,
nsfw: Optional[bool] = None,
language_id: Optional[int] = None,
) -> bool:
"""
Expand Down

0 comments on commit 2e62002

Please sign in to comment.