diff --git a/simnet/client/base.py b/simnet/client/base.py index e45d0e0..566b24a 100644 --- a/simnet/client/base.py +++ b/simnet/client/base.py @@ -18,6 +18,7 @@ from simnet.utils.types import ( RequestData, QueryParamTypes, TimeoutTypes, + URLTypes, ) _LOGGER = logging.getLogger("SIMNet.BaseClient") @@ -223,7 +224,7 @@ class BaseClient(AsyncContextManager["BaseClient"]): async def request( self, method: str, - url: str, + url: URLTypes, data: Optional[RequestData] = None, json: Optional[Any] = None, params: Optional[QueryParamTypes] = None, @@ -237,7 +238,7 @@ class BaseClient(AsyncContextManager["BaseClient"]): Args: method (str): The HTTP method to use for the request (e.g., "GET", "POST"). - url (str): The URL to send the request to. + url (URLTypes): The URL to send the request to. data (Optional[RequestData]): The request data to include in the body of the request. json (Optional[Any]): The JSON payload to include in the body of the request. params (Optional[QueryParamTypes]): The query parameters to include in the request. @@ -268,7 +269,7 @@ class BaseClient(AsyncContextManager["BaseClient"]): async def request_api( self, method: str, - url: str, + url: URLTypes, json: Optional[Any] = None, params: Optional[QueryParamTypes] = None, headers: Optional[HeaderTypes] = None, @@ -281,7 +282,7 @@ class BaseClient(AsyncContextManager["BaseClient"]): Args: method (str): The HTTP method to use for the request (e.g., "GET", "POST"). - url (str): The URL to send the request to. + url (URLTypes): The URL to send the request to. json (Optional[Any]): The JSON payload to include in the body of the request. params (Optional[QueryParamTypes]): The query parameters to include in the request. headers (Optional[HeaderTypes]): The headers to include in the request. @@ -314,7 +315,7 @@ class BaseClient(AsyncContextManager["BaseClient"]): async def request_lab( self, - url: str, + url: URLTypes, method: Optional[str] = None, data: Optional[Any] = None, params: Optional[QueryParamTypes] = None, @@ -330,7 +331,7 @@ class BaseClient(AsyncContextManager["BaseClient"]): It also adds headers for the lab API and handles the case where the method is not specified. Args: - url (str): The URL to send the request to. + url (URLTypes): The URL to send the request to. method (Optional[str]): The HTTP method to use for the request (e.g., "GET", "POST"). data (Optional[Any]): The JSON payload to include in the body of the request. params (Optional[QueryParamTypes]): The query parameters to include in the request. diff --git a/simnet/utils/types.py b/simnet/utils/types.py index 82048f3..8d056c4 100644 --- a/simnet/utils/types.py +++ b/simnet/utils/types.py @@ -2,6 +2,7 @@ from typing import TypeVar, Union, Mapping, Optional, Sequence, Dict, List, Tupl RT = TypeVar("RT", bound="BaseClient") +URLTypes = Union["URL", str] CookieTypes = Union["Cookie", Dict[str, str], List[Tuple[str, str]]] RequestData = Mapping[str, Any]