Skip to content

Commit

Permalink
feat: 移除对 Python 3.8 的支持,升级相关语法
Browse files Browse the repository at this point in the history
  • Loading branch information
FHU-yezi committed Oct 21, 2024
1 parent 044f258 commit 9fd2f2a
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 58 deletions.
4 changes: 2 additions & 2 deletions jkit/_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import ABCMeta, abstractmethod
from typing import Callable, ClassVar, List, Optional
from typing import Callable, ClassVar, Optional

from msgspec import Struct, convert, to_builtins
from msgspec import ValidationError as MsgspecValidationError
Expand All @@ -20,7 +20,7 @@ def _validate(self) -> Self:
raise ValidationError(e.args[0]) from None

def __repr__(self) -> str:
field_strings: List[str] = []
field_strings: list[str] = []
for field in self.__struct_fields__:
value = self.__getattribute__(field)

Expand Down
18 changes: 9 additions & 9 deletions jkit/_network_request.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional
from typing import Any, Optional

from msgspec.json import Decoder

Expand All @@ -12,9 +12,9 @@ async def get_json(
*,
endpoint: str,
path: str,
params: Optional[Dict[str, Any]] = None,
cookies: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:
params: Optional[dict[str, Any]] = None,
cookies: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
response = await HTTP_CLIENT.get(
f"{endpoint}{path}",
params=params,
Expand All @@ -29,11 +29,11 @@ async def send_post(
*,
endpoint: str,
path: str,
params: Optional[Dict[str, Any]] = None,
json: Optional[Dict[str, Any]] = None,
headers: Optional[Dict[str, Any]] = None,
cookies: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:
params: Optional[dict[str, Any]] = None,
json: Optional[dict[str, Any]] = None,
headers: Optional[dict[str, Any]] = None,
cookies: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
response = await HTTP_CLIENT.post(
f"{endpoint}{path}",
params=params,
Expand Down
13 changes: 5 additions & 8 deletions jkit/article.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from collections.abc import AsyncGenerator
from datetime import datetime
from enum import Enum
from typing import (
TYPE_CHECKING,
Any,
AsyncGenerator,
Dict,
List,
Literal,
Optional,
Tuple,
)

from httpx import HTTPStatusError
Expand Down Expand Up @@ -177,7 +174,7 @@ def to_user_obj(self) -> "User":
class ArticleSubcommentInfo(DataObject, **DATA_OBJECT_CONFIG):
id: PositiveInt
content: str
images: Tuple[UserUploadedUrl, ...]
images: tuple[UserUploadedUrl, ...]
published_at: NormalizedDatetime
publisher_info: CommentPublisherInfoField

Expand All @@ -186,12 +183,12 @@ class ArticleCommentInfo(DataObject, **DATA_OBJECT_CONFIG):
id: PositiveInt
floor: PositiveInt
content: str
images: Tuple[UserUploadedUrl, ...]
images: tuple[UserUploadedUrl, ...]
likes_count: NonNegativeInt
published_at: NormalizedDatetime
publisher_info: CommentPublisherInfoField

subcomments: Tuple[ArticleSubcommentInfo, ...]
subcomments: tuple[ArticleSubcommentInfo, ...]

@property
def has_subcomment(self) -> bool:
Expand Down Expand Up @@ -443,7 +440,7 @@ async def iter_featured_comments(
) -> AsyncGenerator[ArticleFeaturedCommentInfo, None]:
await self._auto_check()

data: List[Dict[str, Any]] = await get_json(
data: list[dict[str, Any]] = await get_json(
endpoint=CONFIG.endpoints.jianshu,
path=f"/shakespeare/notes/{self.slug}/featured_comments",
params={
Expand Down
6 changes: 2 additions & 4 deletions jkit/collection.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from collections.abc import AsyncGenerator
from typing import (
TYPE_CHECKING,
Any,
AsyncGenerator,
Dict,
List,
Literal,
Optional,
)
Expand Down Expand Up @@ -169,7 +167,7 @@ async def iter_articles(

now_page = start_page
while True:
data: List[Dict[str, Any]] = await get_json(
data: list[dict[str, Any]] = await get_json(
endpoint=CONFIG.endpoints.jianshu,
path=f"/asimov/collections/slug/{self.slug}/public_notes",
params={
Expand Down
4 changes: 1 addition & 3 deletions jkit/credential.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Dict

from jkit._base import ResourceObject


Expand All @@ -12,5 +10,5 @@ def token(self) -> str:
return self._token

@property
def cookies(self) -> Dict[str, str]:
def cookies(self) -> dict[str, str]:
return {"remember_user_token": self.token}
5 changes: 3 additions & 2 deletions jkit/jpep/ftn_macket.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import AsyncGenerator
from enum import Enum
from typing import AsyncGenerator, Literal, Optional, Tuple
from typing import Literal, Optional

from jkit._base import DATA_OBJECT_CONFIG, DataObject, ResourceObject
from jkit._network_request import send_post
Expand Down Expand Up @@ -39,7 +40,7 @@ class FTNMacketOrderRecord(DataObject, **DATA_OBJECT_CONFIG):

traded_count: NonNegativeInt
publish_time: NormalizedDatetime
supported_payment_channels: Tuple[PaymentChannels, ...]
supported_payment_channels: tuple[PaymentChannels, ...]

publisher_info: PublisherInfoField

Expand Down
5 changes: 3 additions & 2 deletions jkit/lottery.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import TYPE_CHECKING, Any, AsyncGenerator, Dict, List
from collections.abc import AsyncGenerator
from typing import TYPE_CHECKING, Any

from jkit._base import DATA_OBJECT_CONFIG, DataObject, ResourceObject
from jkit._network_request import get_json
Expand Down Expand Up @@ -41,7 +42,7 @@ class Lottery(ResourceObject):
async def iter_win_records(
self, *, count: int = 100
) -> AsyncGenerator[LotteryWinRecord, None]:
data: List[Dict[str, Any]] = await get_json(
data: list[dict[str, Any]] = await get_json(
endpoint=CONFIG.endpoints.jianshu,
path="/asimov/ad_rewards/winner_list",
params={"count": count},
Expand Down
5 changes: 3 additions & 2 deletions jkit/notebook.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import TYPE_CHECKING, Any, AsyncGenerator, Dict, List, Literal, Optional
from collections.abc import AsyncGenerator
from typing import TYPE_CHECKING, Any, Literal, Optional

from httpx import HTTPStatusError
from typing_extensions import Self
Expand Down Expand Up @@ -157,7 +158,7 @@ async def iter_articles(

now_page = start_page
while True:
data: List[Dict[str, Any]] = await get_json(
data: list[dict[str, Any]] = await get_json(
endpoint=CONFIG.endpoints.jianshu,
path=f"/asimov/notebooks/{self.id}/public_notes",
params={
Expand Down
3 changes: 2 additions & 1 deletion jkit/private/assets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from collections.abc import AsyncGenerator
from contextlib import suppress
from datetime import datetime
from decimal import Decimal
from typing import AsyncGenerator, Optional, Union
from typing import Optional, Union

from httpx import HTTPStatusError
from msgspec import DecodeError
Expand Down
5 changes: 3 additions & 2 deletions jkit/ranking/article_earning.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import AsyncGenerator
from datetime import date, datetime, timedelta
from typing import TYPE_CHECKING, AsyncGenerator, Optional, Tuple
from typing import TYPE_CHECKING, Optional

from jkit._base import DATA_OBJECT_CONFIG, DataObject, ResourceObject
from jkit._network_request import get_json
Expand Down Expand Up @@ -50,7 +51,7 @@ class ArticleEarningRankingData(DataObject, **DATA_OBJECT_CONFIG):
total_fp_amount_sum: PositiveFloat
fp_to_author_amount_sum: PositiveFloat
fp_to_voter_amount_sum: PositiveFloat
records: Tuple[RecordField, ...]
records: tuple[RecordField, ...]


class ArticleEarningRanking(ResourceObject):
Expand Down
3 changes: 2 additions & 1 deletion jkit/ranking/assets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import TYPE_CHECKING, AsyncGenerator, Optional
from collections.abc import AsyncGenerator
from typing import TYPE_CHECKING, Optional

from jkit._base import DATA_OBJECT_CONFIG, DataObject, ResourceObject
from jkit._network_request import get_json
Expand Down
3 changes: 2 additions & 1 deletion jkit/ranking/daily_update.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import TYPE_CHECKING, AsyncGenerator
from collections.abc import AsyncGenerator
from typing import TYPE_CHECKING

from jkit._base import DATA_OBJECT_CONFIG, DataObject, ResourceObject
from jkit._network_request import get_json
Expand Down
5 changes: 3 additions & 2 deletions jkit/ranking/user_earning.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import AsyncGenerator
from datetime import date, datetime, timedelta
from typing import TYPE_CHECKING, AsyncGenerator, Literal, Optional, Tuple
from typing import TYPE_CHECKING, Literal, Optional

from jkit._base import DATA_OBJECT_CONFIG, DataObject, ResourceObject
from jkit._network_request import get_json
Expand Down Expand Up @@ -38,7 +39,7 @@ class UserEarningRankingData(DataObject, **DATA_OBJECT_CONFIG):
total_fp_amount_sum: PositiveFloat
fp_by_creating_amount_sum: PositiveFloat
fp_by_voting_amount_sum: PositiveFloat
records: Tuple[RecordField, ...]
records: tuple[RecordField, ...]


class UserEarningRanking(ResourceObject):
Expand Down
9 changes: 3 additions & 6 deletions jkit/user.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from collections.abc import AsyncGenerator
from enum import Enum
from re import compile as re_compile
from typing import (
TYPE_CHECKING,
Any,
AsyncGenerator,
Dict,
List,
Literal,
Optional,
Tuple,
)

from httpx import HTTPStatusError
Expand Down Expand Up @@ -82,7 +79,7 @@ class UserInfo(DataObject, **DATA_OBJECT_CONFIG):
introduction_updated_at: NormalizedDatetime
avatar_url: UserUploadedUrl
background_image_url: Optional[UserUploadedUrl]
badges: Tuple[UserBadge, ...]
badges: tuple[UserBadge, ...]
membership_info: MembershipInfoField
address_by_ip: NonEmptyStr

Expand Down Expand Up @@ -368,7 +365,7 @@ async def iter_articles(

now_page = start_page
while True:
data: List[Dict[str, Any]] = await get_json(
data: list[dict[str, Any]] = await get_json(
endpoint=CONFIG.endpoints.jianshu,
path=f"/asimov/users/slug/{self.slug}/public_notes",
params={
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ classifiers = [
"Topic :: Software Development :: Libraries",
"Typing :: Typed",
]
requires-python = ">=3.8"
requires-python = ">=3.9"
dependencies = [
"httpx[http2]",
"msgspec",
Expand All @@ -32,7 +32,7 @@ dev-dependencies = [
]

[tool.ruff]
target-version = "py38"
target-version = "py39"
lint.select = [
"A", "ANN", "ARG", "ASYNC", "B",
"BLE", "C4", "E", "F", "I",
Expand Down
15 changes: 4 additions & 11 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9fd2f2a

Please sign in to comment.