refactor(types): govern TMDb keyword response contract

This commit is contained in:
jxxghp
2026-10-17 00:11:39 +08:00
parent 1a1bcbb517
commit 21251ee347
2 changed files with 8 additions and 5 deletions

View File

@@ -1,13 +1,15 @@
from ..tmdb import TMDb
from ..tmdb import TMDb, TMDbJson
class Keyword(TMDb):
"""提供关键词详情与关联电影查询。"""
_urls = {
"details": "/keyword/%s",
"movies": "/keyword/%s/movies"
}
def details(self, keyword_id):
def details(self, keyword_id: int | str) -> TMDbJson:
"""
Get a keywords details by id.
:param keyword_id: int
@@ -15,7 +17,7 @@ class Keyword(TMDb):
"""
return self._request_obj(self._urls["details"] % keyword_id)
def movies(self, keyword_id):
def movies(self, keyword_id: int | str) -> TMDbJson:
"""
Get the movies of a keyword by id.
:param keyword_id: int
@@ -24,7 +26,7 @@ class Keyword(TMDb):
return self._request_obj(self._urls["movies"] % keyword_id, key="results")
# 异步版本方法
async def async_details(self, keyword_id):
async def async_details(self, keyword_id: int | str) -> TMDbJson:
"""
Get a keywords details by id.(异步版本)
:param keyword_id: int
@@ -32,7 +34,7 @@ class Keyword(TMDb):
"""
return await self._async_request_obj(self._urls["details"] % keyword_id)
async def async_movies(self, keyword_id):
async def async_movies(self, keyword_id: int | str) -> TMDbJson:
"""
Get the movies of a keyword by id.(异步版本)
:param keyword_id: int

View File

@@ -183,4 +183,5 @@ files =
app/modules/themoviedb/tmdbv3api/objs/group.py,
app/modules/themoviedb/tmdbv3api/objs/network.py,
app/modules/themoviedb/tmdbv3api/objs/company.py,
app/modules/themoviedb/tmdbv3api/objs/keyword.py,
scripts/architecture/async_blocking.py