Skip to content

Commit

Permalink
chore: deprecation reminder
Browse files Browse the repository at this point in the history
  • Loading branch information
shengchenyang committed Dec 28, 2024
1 parent 83815e5 commit 3d34e99
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion ayugespidertools/common/typevars.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import threading
from enum import Enum
from typing import TYPE_CHECKING, Any, Literal, NamedTuple, TypeVar, Union

from sqlalchemy import create_engine
Expand All @@ -18,8 +19,10 @@
NoneType = type(None)
I_Str = TypeVar("I_Str", int, str)
B_Str = TypeVar("B_Str", bytes, str)
I_Str_N = TypeVar("I_Str_N", int, str, NoneType)
I_Str_N = TypeVar("I_Str_N", int, str, None)
Str_Lstr = TypeVar("Str_Lstr", str, list[str])
_SENTINEL = Enum("_SENTINEL", "sentinel")
sentinel = _SENTINEL.sentinel

AiohttpRequestMethodStr = Literal[
"GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "PATCH"
Expand Down
8 changes: 8 additions & 0 deletions ayugespidertools/scraper/http/request/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

from scrapy import Request

from ayugespidertools.common.typevars import _SENTINEL, sentinel
from ayugespidertools.config import logger

__all__ = [
"AiohttpRequest",
]
Expand Down Expand Up @@ -45,6 +48,7 @@ def __init__(
callback: CallbackT | None = None,
method: str = "GET",
headers: Mapping[AnyStr, Any] | Iterable[tuple[AnyStr, Any]] | None = None,
body: _SENTINEL = sentinel,
cookies: CookiesT | None = None,
meta: dict[str, Any] | None = None,
encoding: str = "utf-8",
Expand Down Expand Up @@ -82,6 +86,10 @@ def __init__(
max_field_size: int | None = None,
timeout: ClientTimeout | None = None,
) -> None:
if body is not sentinel:
logger.error(
"parameter 'body' is deprecated, use 'json' or 'data' argument instead"
)

aiohttp_req_args = {
"method": method,
Expand Down
4 changes: 2 additions & 2 deletions ayugespidertools/scraper/middlewares/netlib/aiohttplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AiohttpDownloaderMiddleware:
def _retry(
self,
request: AyuRequest,
reason: int,
reason: str | int,
spider: AyuSpider,
) -> AyuRequest | None:
"""重试请求
Expand All @@ -70,7 +70,7 @@ def _retry_with_limit(
self,
request: AyuRequest,
retries: int,
reason: str,
reason: str | int,
stats: StatsCollector,
):
logger.debug(f"Retrying {request} (failed {retries} times): {reason}")
Expand Down

0 comments on commit 3d34e99

Please sign in to comment.