From b2b8cd979d2bb0f50a5e9becd556e561903127b7 Mon Sep 17 00:00:00 2001 From: Amit Kumar Yadav <39150741+savewater1@users.noreply.github.com> Date: Thu, 24 Apr 2025 16:04:52 -0400 Subject: [PATCH] Fix type hinting Use Union type from typing instead of the pipe '|' operator for type hinting when the type of return value is conditional --- src/oxylabs/internal/api.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/oxylabs/internal/api.py b/src/oxylabs/internal/api.py index dc864b8..17e9c22 100644 --- a/src/oxylabs/internal/api.py +++ b/src/oxylabs/internal/api.py @@ -3,6 +3,7 @@ import requests import aiohttp import asyncio +from typing import Union from platform import python_version, architecture from oxylabs._version import __version__ from oxylabs.utils.defaults import ASYNC_BASE_URL, SYNC_BASE_URL @@ -68,7 +69,7 @@ def get_response(self, payload:dict, config:dict) -> dict: return self._get_http_response(payload, "POST", config) - def _get_http_response(self, payload: dict, method: str, config: dict) -> dict | None: + def _get_http_response(self, payload: dict, method: str, config: dict) -> Union[dict, None]: """ Sends an HTTP request to the specified URL with the given payload and method. @@ -136,7 +137,7 @@ def __init__(self, api_credentials: APICredentials, **kwargs) -> None: self._session = None self._requests = 0 - async def get_response(self, payload: dict, config: dict) -> dict | None: + async def get_response(self, payload: dict, config: dict) -> Union[dict, None]: """ Processes the payload asynchronously and fetches the response. @@ -175,7 +176,7 @@ async def _get_job_id( payload: dict, user_session: aiohttp.ClientSession, request_timeout: int, - ) -> str | None: + ) -> Union[str, None]: try: async with user_session.post( self._base_url, @@ -232,7 +233,7 @@ async def _poll_job_status( async def _get_http_response( self, job_id: str, user_session: aiohttp.ClientSession - ) -> dict | None: + ) -> Union[dict, None]: """ Retrieves the HTTP response for a given job ID. @@ -291,4 +292,4 @@ async def _execute_with_timeout( logger.error("Job did not complete successfully") result = await self._get_http_response(job_id, user_session) - return result \ No newline at end of file + return result