refactor(types): govern TMDb company response contract

This commit is contained in:
jxxghp
2026-10-16 23:49:58 +08:00
parent ac6813bc60
commit a4062323fd
2 changed files with 12 additions and 9 deletions

View File

@@ -1,7 +1,9 @@
from ..tmdb import TMDb
from ..tmdb import TMDb, TMDbJson
class Company(TMDb):
"""提供公司详情、别名、图像和电影分页查询。"""
_urls = {
"details": "/company/%s",
"alternative_names": "/company/%s/alternative_names",
@@ -9,7 +11,7 @@ class Company(TMDb):
"movies": "/company/%s/movies"
}
def details(self, company_id):
def details(self, company_id: int | str) -> TMDbJson:
"""
Get a companies details by id.
:param company_id: int
@@ -17,7 +19,7 @@ class Company(TMDb):
"""
return self._request_obj(self._urls["details"] % company_id)
def alternative_names(self, company_id):
def alternative_names(self, company_id: int | str) -> TMDbJson:
"""
Get the alternative names of a company.
:param company_id: int
@@ -25,7 +27,7 @@ class Company(TMDb):
"""
return self._request_obj(self._urls["alternative_names"] % company_id, key="results")
def images(self, company_id):
def images(self, company_id: int | str) -> TMDbJson:
"""
Get the alternative names of a company.
:param company_id: int
@@ -33,7 +35,7 @@ class Company(TMDb):
"""
return self._request_obj(self._urls["images"] % company_id, key="logos")
def movies(self, company_id, page=1):
def movies(self, company_id: int | str, page: int=1) -> TMDbJson:
"""
Get the movies of a company by id.
:param company_id: int
@@ -47,7 +49,7 @@ class Company(TMDb):
)
# 异步版本方法
async def async_details(self, company_id):
async def async_details(self, company_id: int | str) -> TMDbJson:
"""
Get a companies details by id.(异步版本)
:param company_id: int
@@ -55,7 +57,7 @@ class Company(TMDb):
"""
return await self._async_request_obj(self._urls["details"] % company_id)
async def async_alternative_names(self, company_id):
async def async_alternative_names(self, company_id: int | str) -> TMDbJson:
"""
Get the alternative names of a company.(异步版本)
:param company_id: int
@@ -63,7 +65,7 @@ class Company(TMDb):
"""
return await self._async_request_obj(self._urls["alternative_names"] % company_id, key="results")
async def async_images(self, company_id):
async def async_images(self, company_id: int | str) -> TMDbJson:
"""
Get the alternative names of a company.(异步版本)
:param company_id: int
@@ -71,7 +73,7 @@ class Company(TMDb):
"""
return await self._async_request_obj(self._urls["images"] % company_id, key="logos")
async def async_movies(self, company_id, page=1):
async def async_movies(self, company_id: int | str, page: int=1) -> TMDbJson:
"""
Get the movies of a company by id.(异步版本)
:param company_id: int

View File

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