Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix httpresponse/requesttype is unbound in retry + contravariant sans…
…io policy
  • Loading branch information
swathipil committed Feb 20, 2024
commit 729841013ae3b884e2838b77b0880ef1440ff85a
10 changes: 6 additions & 4 deletions sdk/core/corehttp/corehttp/runtime/policies/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

HTTPResponseType = TypeVar("HTTPResponseType")
HTTPRequestType = TypeVar("HTTPRequestType")
SansIOHTTPResponseType_contra = TypeVar("SansIOHTTPResponseType_contra", contravariant=True)
SansIOHTTPRequestType_contra = TypeVar("SansIOHTTPRequestType_contra", contravariant=True)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -62,7 +64,7 @@ def send(self, request: PipelineRequest[HTTPRequestType]) -> PipelineResponse[HT


@runtime_checkable
class SansIOHTTPPolicy(Generic[HTTPRequestType, HTTPResponseType], Protocol):
class SansIOHTTPPolicy(Generic[SansIOHTTPRequestType_contra, SansIOHTTPResponseType_contra], Protocol):
"""Represents a sans I/O policy.

SansIOHTTPPolicy is a protocol for policies that only modify or
Expand All @@ -74,7 +76,7 @@ class SansIOHTTPPolicy(Generic[HTTPRequestType, HTTPResponseType], Protocol):
but they will then be tied to AsyncPipeline usage.
"""

def on_request(self, request: PipelineRequest[HTTPRequestType]) -> Union[None, Awaitable[None]]:
def on_request(self, request: PipelineRequest[SansIOHTTPRequestType_contra]) -> Union[None, Awaitable[None]]:
"""Is executed before sending the request from next policy.

:param request: Request to be modified before sent from next policy.
Expand All @@ -83,8 +85,8 @@ def on_request(self, request: PipelineRequest[HTTPRequestType]) -> Union[None, A

def on_response(
self,
request: PipelineRequest[HTTPRequestType],
response: PipelineResponse[HTTPRequestType, HTTPResponseType],
request: PipelineRequest[SansIOHTTPRequestType_contra],
response: PipelineResponse[SansIOHTTPRequestType_contra, SansIOHTTPResponseType_contra],
) -> Union[None, Awaitable[None]]:
"""Is executed after the request comes back from the policy.

Expand Down
1 change: 0 additions & 1 deletion sdk/core/corehttp/corehttp/runtime/policies/_base_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from ...runtime.pipeline import PipelineRequest, PipelineResponse

AsyncHTTPResponseType = TypeVar("AsyncHTTPResponseType")
HTTPResponseType = TypeVar("HTTPResponseType")
HTTPRequestType = TypeVar("HTTPRequestType")


Expand Down
4 changes: 1 addition & 3 deletions sdk/core/corehttp/corehttp/runtime/policies/_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@

AllHttpResponseType = TypeVar("AllHttpResponseType", HttpResponse, AsyncHttpResponse)
ClsRetryPolicy = TypeVar("ClsRetryPolicy", bound="RetryPolicyBase")
HTTPResponseType = TypeVar("HTTPResponseType")
HTTPRequestType = TypeVar("HTTPRequestType")

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -421,7 +419,7 @@ class RetryPolicy(RetryPolicyBase, HTTPPolicy[HttpRequest, HttpResponse]):
:keyword int timeout: Timeout setting for the operation in seconds, default is 604800s (7 days).
"""

next: "HTTPPolicy[HTTPRequestType, HTTPResponseType]"
next: "HTTPPolicy[HttpRequest, HttpResponse]"
"""Pointer to the next policy or a transport (wrapped as a policy). Will be set at pipeline creation."""

def _sleep_for_retry(
Expand Down
4 changes: 1 addition & 3 deletions sdk/core/corehttp/corehttp/runtime/policies/_retry_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@

_LOGGER = logging.getLogger(__name__)

AsyncHTTPResponseType = TypeVar("AsyncHTTPResponseType")
HTTPRequestType = TypeVar("HTTPRequestType")

class AsyncRetryPolicy(RetryPolicyBase, AsyncHTTPPolicy[HttpRequest, AsyncHttpResponse]):
"""Async flavor of the retry policy.
Expand Down Expand Up @@ -76,7 +74,7 @@ class AsyncRetryPolicy(RetryPolicyBase, AsyncHTTPPolicy[HttpRequest, AsyncHttpRe
:keyword int retry_backoff_max: The maximum back off time. Default value is 120 seconds (2 minutes).
"""

next: "AsyncHTTPPolicy[HTTPRequestType, AsyncHTTPResponseType]"
next: "AsyncHTTPPolicy[HttpRequest, AsyncHttpResponse]"
"""Pointer to the next policy or a transport (wrapped as a policy). Will be set at pipeline creation."""

async def _sleep_for_retry(
Expand Down