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
update sansiohttppolicy on_response/on_request to return None for mypy
  • Loading branch information
swathipil committed Feb 22, 2024
commit 31dc887ee53cec243b4771168a077700a18d3a2d
4 changes: 2 additions & 2 deletions sdk/core/corehttp/corehttp/runtime/pipeline/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ def __init__(
self._impl_policies.append(policy)
elif isinstance(policy, SansIOHTTPPolicy):
self._impl_policies.append(_SansIOHTTPPolicyRunner(policy))
else:
raise TypeError("Unsupported policy type: {}".format(type(policy)))
elif policy:
self._impl_policies.append(policy)
for index in range(len(self._impl_policies) - 1):
self._impl_policies[index].next = self._impl_policies[index + 1]
if self._impl_policies:
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/corehttp/corehttp/runtime/pipeline/_base_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def __init__(
self._impl_policies.append(policy)
elif isinstance(policy, SansIOHTTPPolicy):
self._impl_policies.append(_SansIOAsyncHTTPPolicyRunner(policy))
else:
raise TypeError("Unsupported policy type: {}".format(type(policy)))
elif policy:
self._impl_policies.append(policy)
for index in range(len(self._impl_policies) - 1):
self._impl_policies[index].next = self._impl_policies[index + 1]
if self._impl_policies:
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/corehttp/corehttp/runtime/policies/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def on_request(self, request: PipelineRequest[SansIOHTTPRequestType_contra]) ->
:param request: Request to be modified before sent from next policy.
:type request: ~corehttp.runtime.pipeline.PipelineRequest
"""
...
return None

def on_response(
self,
Expand All @@ -97,7 +97,7 @@ def on_response(
:param response: Pipeline response object
:type response: ~corehttp.runtime.pipeline.PipelineResponse
"""
...
return None


class RequestHistory(Generic[HTTPRequestType, HTTPResponseType]):
Expand Down
42 changes: 0 additions & 42 deletions sdk/core/corehttp/corehttp/runtime/policies/_universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,6 @@ def on_request(self, request: PipelineRequest[HTTPRequestType]) -> None:
if additional_headers:
request.http_request.headers.update(additional_headers)

def on_response( # pylint: disable=unused-argument
self,
request: PipelineRequest[HTTPRequestType],
response: PipelineResponse[HTTPRequestType, HTTPResponseType],
) -> Union[None, Awaitable[None]]:
"""Is executed after the request comes back from the policy.

:param request: Request to be modified after returning from the policy.
:type request: ~corehttp.runtime.pipeline.PipelineRequest
:param response: Pipeline response object
:type response: ~corehttp.runtime.pipeline.PipelineResponse
"""
return None


class UserAgentPolicy(SansIOHTTPPolicy[HTTPRequestType, HTTPResponseType]):
"""User-Agent Policy. Allows custom values to be added to the User-Agent header.
Expand Down Expand Up @@ -184,20 +170,6 @@ def on_request(self, request: PipelineRequest[HTTPRequestType]) -> None:
elif self.overwrite or self._USERAGENT not in http_request.headers:
http_request.headers[self._USERAGENT] = self.user_agent

def on_response( # pylint: disable=unused-argument
self,
request: PipelineRequest[HTTPRequestType],
response: PipelineResponse[HTTPRequestType, HTTPResponseType],
) -> Union[None, Awaitable[None]]:
"""Is executed after the request comes back from the policy.

:param request: Request to be modified after returning from the policy.
:type request: ~corehttp.runtime.pipeline.PipelineRequest
:param response: Pipeline response object
:type response: ~corehttp.runtime.pipeline.PipelineResponse
"""
return None


class NetworkTraceLoggingPolicy(SansIOHTTPPolicy[HTTPRequestType, HTTPResponseType]):

Expand Down Expand Up @@ -490,17 +462,3 @@ def on_request(self, request: PipelineRequest[HTTPRequestType]) -> None:
ctxt = request.context.options
if self.proxies and "proxies" not in ctxt:
ctxt["proxies"] = self.proxies

def on_response( # pylint: disable=unused-argument
self,
request: PipelineRequest[HTTPRequestType],
response: PipelineResponse[HTTPRequestType, HTTPResponseType],
) -> Union[None, Awaitable[None]]:
"""Is executed after the request comes back from the policy.

:param request: Request to be modified after returning from the policy.
:type request: ~corehttp.runtime.pipeline.PipelineRequest
:param response: Pipeline response object
:type response: ~corehttp.runtime.pipeline.PipelineResponse
"""
return None