From b8f27474d7dfd30f3537d506b819586fa39d089f Mon Sep 17 00:00:00 2001 From: Yifei Kong Date: Fri, 2 Aug 2024 13:30:18 +0800 Subject: [PATCH] Change http method typehints to literal of methods --- curl_cffi/requests/__init__.py | 4 ++-- curl_cffi/requests/session.py | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/curl_cffi/requests/__init__.py b/curl_cffi/requests/__init__.py index c37b51f..3f66a77 100644 --- a/curl_cffi/requests/__init__.py +++ b/curl_cffi/requests/__init__.py @@ -37,12 +37,12 @@ from .headers import Headers, HeaderTypes from .impersonate import BrowserType, BrowserTypeLiteral, ExtraFingerprints, ExtraFpDict from .models import Request, Response -from .session import AsyncSession, ProxySpec, Session, ThreadType +from .session import AsyncSession, HttpMethod, ProxySpec, Session, ThreadType from .websockets import WebSocket, WebSocketError, WsCloseCode def request( - method: str, + method: HttpMethod, url: str, params: Optional[Union[Dict, List, Tuple]] = None, data: Optional[Union[Dict[str, str], List[Tuple], str, BytesIO, bytes]] = None, diff --git a/curl_cffi/requests/session.py b/curl_cffi/requests/session.py index 18f0e76..1d5333d 100644 --- a/curl_cffi/requests/session.py +++ b/curl_cffi/requests/session.py @@ -92,6 +92,7 @@ class BaseSessionParams(TypedDict, total=False): BaseSessionParams = TypedDict ThreadType = Literal["eventlet", "gevent"] +HttpMethod = Literal["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "TRACE"] def _is_absolute_url(url: str) -> bool: @@ -346,7 +347,7 @@ def _set_extra_fp(self, curl, fp: ExtraFingerprints): def _set_curl_options( self, curl, - method: str, + method: HttpMethod, url: str, params: Optional[Union[Dict, List, Tuple]] = None, data: Optional[Union[Dict[str, str], List[Tuple], str, BytesIO, bytes]] = None, @@ -888,7 +889,7 @@ def ws_connect( def request( self, - method: str, + method: HttpMethod, url: str, params: Optional[Union[Dict, List, Tuple]] = None, data: Optional[Union[Dict[str, str], List[Tuple], str, BytesIO, bytes]] = None, @@ -1180,7 +1181,7 @@ async def ws_connect(self, url, *args, **kwargs): async def request( self, - method: str, + method: HttpMethod, url: str, params: Optional[Union[Dict, List, Tuple]] = None, data: Optional[Union[Dict[str, str], List[Tuple], str, BytesIO, bytes]] = None,