Skip to content

Commit

Permalink
style: mypy check
Browse files Browse the repository at this point in the history
  • Loading branch information
shengchenyang committed Mar 5, 2024
1 parent f0f1b2f commit 3ae246a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
8 changes: 4 additions & 4 deletions ayugespidertools/common/typevars.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class AlterItem(NamedTuple):
new_item: dict
notes_dic: dict
table: AlterItemTable
is_namedtuple: Optional[bool] = False
is_namedtuple: bool = False


@dataclass
Expand Down Expand Up @@ -195,9 +195,9 @@ class OssConf(NamedTuple):
endpoint: str
bucket: str
doc: Optional[str] = None
upload_fields_suffix: Optional[str] = "_file_url"
oss_fields_prefix: Optional[str] = "_"
full_link_enable: Optional[bool] = False
upload_fields_suffix: str = "_file_url"
oss_fields_prefix: str = "_"
full_link_enable: bool = False


class FieldAlreadyExistsError(Exception):
Expand Down
7 changes: 5 additions & 2 deletions ayugespidertools/scraper/pipelines/download/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
__all__ = ["FilesDownloadPipeline"]

if TYPE_CHECKING:
from scrapy.crawler import Crawler
from typing_extensions import Self

from ayugespidertools.common.typevars import AlterItem
from ayugespidertools.spiders import AyuSpider

Expand All @@ -18,7 +21,7 @@ def __init__(self, file_path=None):
self.file_path = file_path

@classmethod
def from_crawler(cls, crawler):
def from_crawler(cls, crawler: "Crawler") -> "Self":
_file_path = crawler.settings.get("FILES_STORE", None)
assert _file_path is not None, "未配置 FILES_STORE 存储路径参数!"

Expand Down Expand Up @@ -48,7 +51,7 @@ async def _download_and_add_field(
key_value=filename, notes=f"{key} 文件存储路径"
)

async def process_item(self, item: Any, spider: "AyuSpider"):
async def process_item(self, item: Any, spider: "AyuSpider") -> Any:
item_dict = ReuseOperation.item_to_dict(item)
alter_item = ReuseOperation.reshape_item(item_dict)
await self._download_and_add_field(alter_item, item, spider)
Expand Down
4 changes: 2 additions & 2 deletions ayugespidertools/scraper/pipelines/oss/ali.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AyuAsyncOssPipeline:
slog: "slogT"
full_link_enable: bool

def open_spider(self, spider: "AyuSpider"):
def open_spider(self, spider: "AyuSpider") -> None:
assert hasattr(spider, "oss_conf"), "未配置 oss 参数!"
self.oss_conf = spider.oss_conf
oss_conf_dict = self.oss_conf._asdict()
Expand Down Expand Up @@ -87,7 +87,7 @@ async def _upload_file(
filename = await self._upload_process(url, spider)
self._add_oss_field(_is_namedtuple, item, key, filename)

async def process_item(self, item: Any, spider: "AyuSpider"):
async def process_item(self, item: Any, spider: "AyuSpider") -> Any:
item_dict = ReuseOperation.item_to_dict(item)
alter_item = ReuseOperation.reshape_item(item_dict)
await self._upload_file(alter_item, item, spider)
Expand Down

0 comments on commit 3ae246a

Please sign in to comment.