Skip to content

Commit a0b17e3

Browse files
next-pylint azure-core / corehttp (#35216)
* next-pylint azure-core * next-pylint corehttp * fix mypy * apply azure-core change to corehttp
1 parent 11fd092 commit a0b17e3

File tree

8 files changed

+87
-60
lines changed

8 files changed

+87
-60
lines changed

sdk/core/azure-core/azure/core/pipeline/_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ def send(self, request: PipelineRequest[HTTPRequestType]) -> PipelineResponse[HT
8787
except Exception: # pylint: disable=broad-except
8888
_await_result(self._policy.on_exception, request)
8989
raise
90-
else:
91-
_await_result(self._policy.on_response, request, response)
90+
_await_result(self._policy.on_response, request, response)
9291
return response
9392

9493

sdk/core/azure-core/azure/core/pipeline/_base_async.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ async def send(
7070
except Exception: # pylint: disable=broad-except
7171
await _await_result(self._policy.on_exception, request)
7272
raise
73-
else:
74-
await _await_result(self._policy.on_response, request, response)
73+
await _await_result(self._policy.on_response, request, response)
7574
return response
7675

7776

sdk/core/azure-core/azure/core/pipeline/policies/_authentication.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,26 +124,26 @@ def send(self, request: PipelineRequest[HTTPRequestType]) -> PipelineResponse[HT
124124
self.on_request(request)
125125
try:
126126
response = self.next.send(request)
127-
self.on_response(request, response)
128127
except Exception: # pylint:disable=broad-except
129128
self.on_exception(request)
130129
raise
131-
else:
132-
if response.http_response.status_code == 401:
133-
self._token = None # any cached token is invalid
134-
if "WWW-Authenticate" in response.http_response.headers:
135-
request_authorized = self.on_challenge(request, response)
136-
if request_authorized:
137-
# if we receive a challenge response, we retrieve a new token
138-
# which matches the new target. In this case, we don't want to remove
139-
# token from the request so clear the 'insecure_domain_change' tag
140-
request.context.options.pop("insecure_domain_change", False)
141-
try:
142-
response = self.next.send(request)
143-
self.on_response(request, response)
144-
except Exception: # pylint:disable=broad-except
145-
self.on_exception(request)
146-
raise
130+
131+
self.on_response(request, response)
132+
if response.http_response.status_code == 401:
133+
self._token = None # any cached token is invalid
134+
if "WWW-Authenticate" in response.http_response.headers:
135+
request_authorized = self.on_challenge(request, response)
136+
if request_authorized:
137+
# if we receive a challenge response, we retrieve a new token
138+
# which matches the new target. In this case, we don't want to remove
139+
# token from the request so clear the 'insecure_domain_change' tag
140+
request.context.options.pop("insecure_domain_change", False)
141+
try:
142+
response = self.next.send(request)
143+
self.on_response(request, response)
144+
except Exception: # pylint:disable=broad-except
145+
self.on_exception(request)
146+
raise
147147

148148
return response
149149

sdk/core/azure-core/azure/core/pipeline/policies/_authentication_async.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ async def send(
102102
except Exception: # pylint:disable=broad-except
103103
await await_result(self.on_exception, request)
104104
raise
105-
else:
106-
await await_result(self.on_response, request, response)
105+
await await_result(self.on_response, request, response)
107106

108107
if response.http_response.status_code == 401:
109108
self._token = None # any cached token is invalid
@@ -119,8 +118,7 @@ async def send(
119118
except Exception: # pylint:disable=broad-except
120119
await await_result(self.on_exception, request)
121120
raise
122-
else:
123-
await await_result(self.on_response, request, response)
121+
await await_result(self.on_response, request, response)
124122

125123
return response
126124

sdk/core/azure-core/azure/core/tracing/decorator.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727

2828
import functools
2929

30-
from typing import Callable, Any, TypeVar, overload, Optional
30+
from typing import Callable, Any, TypeVar, overload, Optional, Mapping, TYPE_CHECKING
3131
from typing_extensions import ParamSpec
3232
from .common import change_context, get_function_and_class_name
3333
from . import SpanKind as _SpanKind
3434
from ..settings import settings
3535

36+
if TYPE_CHECKING:
37+
from azure.core.tracing import SpanKind
3638

3739
P = ParamSpec("P")
3840
T = TypeVar("T")
@@ -44,28 +46,42 @@ def distributed_trace(__func: Callable[P, T]) -> Callable[P, T]:
4446

4547

4648
@overload
47-
def distributed_trace( # pylint:disable=function-redefined
48-
**kwargs: Any, # pylint:disable=unused-argument
49+
def distributed_trace(
50+
*,
51+
name_of_span: Optional[str] = None,
52+
kind: Optional["SpanKind"] = None,
53+
tracing_attributes: Optional[Mapping[str, Any]] = None,
54+
**kwargs: Any,
4955
) -> Callable[[Callable[P, T]], Callable[P, T]]:
5056
pass
5157

5258

5359
def distributed_trace(
54-
__func: Optional[Callable[P, T]] = None, **kwargs: Any
55-
) -> Any: # pylint:disable=function-redefined
60+
__func: Optional[Callable[P, T]] = None, # pylint: disable=unused-argument
61+
*,
62+
name_of_span: Optional[str] = None,
63+
kind: Optional["SpanKind"] = None,
64+
tracing_attributes: Optional[Mapping[str, Any]] = None,
65+
**kwargs: Any,
66+
) -> Any:
5667
"""Decorator to apply to function to get traced automatically.
5768
5869
Span will use the func name or "name_of_span".
5970
60-
:param callable func: A function to decorate
71+
:param callable __func: A function to decorate
6172
:keyword name_of_span: The span name to replace func name if necessary
6273
:paramtype name_of_span: str
6374
:keyword kind: The kind of the span. INTERNAL by default.
6475
:paramtype kind: ~azure.core.tracing.SpanKind
76+
:keyword tracing_attributes: Attributes to add to the span.
77+
:paramtype tracing_attributes: Mapping[str, Any] or None
78+
:return: The decorated function
79+
:rtype: Any
6580
"""
66-
name_of_span = kwargs.pop("name_of_span", None)
67-
tracing_attributes = kwargs.pop("tracing_attributes", {})
68-
kind = kwargs.pop("kind", _SpanKind.INTERNAL)
81+
if tracing_attributes is None:
82+
tracing_attributes = {}
83+
if kind is None:
84+
kind = _SpanKind.INTERNAL
6985

7086
def decorator(func: Callable[P, T]) -> Callable[P, T]:
7187
@functools.wraps(func)

sdk/core/azure-core/azure/core/tracing/decorator_async.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@
2727

2828
import functools
2929

30-
from typing import Awaitable, Callable, Any, TypeVar, overload, Optional
30+
from typing import Awaitable, Callable, Any, TypeVar, overload, Optional, Mapping, TYPE_CHECKING
3131
from typing_extensions import ParamSpec
3232
from .common import change_context, get_function_and_class_name
3333
from . import SpanKind as _SpanKind
3434
from ..settings import settings
3535

36+
if TYPE_CHECKING:
37+
from azure.core.tracing import SpanKind
38+
3639
P = ParamSpec("P")
3740
T = TypeVar("T")
3841

@@ -43,28 +46,42 @@ def distributed_trace_async(__func: Callable[P, Awaitable[T]]) -> Callable[P, Aw
4346

4447

4548
@overload
46-
def distributed_trace_async( # pylint:disable=function-redefined
47-
**kwargs: Any, # pylint:disable=unused-argument
49+
def distributed_trace_async(
50+
*,
51+
name_of_span: Optional[str] = None,
52+
kind: Optional["SpanKind"] = None,
53+
tracing_attributes: Optional[Mapping[str, Any]] = None,
54+
**kwargs: Any,
4855
) -> Callable[[Callable[P, Awaitable[T]]], Callable[P, Awaitable[T]]]:
4956
pass
5057

5158

52-
def distributed_trace_async( # pylint:disable=function-redefined
53-
__func: Optional[Callable[P, Awaitable[T]]] = None, **kwargs: Any
59+
def distributed_trace_async(
60+
__func: Optional[Callable[P, Awaitable[T]]] = None, # pylint: disable=unused-argument
61+
*,
62+
name_of_span: Optional[str] = None,
63+
kind: Optional["SpanKind"] = None,
64+
tracing_attributes: Optional[Mapping[str, Any]] = None,
65+
**kwargs: Any,
5466
) -> Any:
5567
"""Decorator to apply to function to get traced automatically.
5668
5769
Span will use the func name or "name_of_span".
5870
59-
:param callable func: A function to decorate
71+
:param callable __func: A function to decorate
6072
:keyword name_of_span: The span name to replace func name if necessary
6173
:paramtype name_of_span: str
6274
:keyword kind: The kind of the span. INTERNAL by default.
6375
:paramtype kind: ~azure.core.tracing.SpanKind
76+
:keyword tracing_attributes: Attributes to add to the span.
77+
:paramtype tracing_attributes: Mapping[str, Any] or None
78+
:return: The decorated function
79+
:rtype: Any
6480
"""
65-
name_of_span = kwargs.pop("name_of_span", None)
66-
tracing_attributes = kwargs.pop("tracing_attributes", {})
67-
kind = kwargs.pop("kind", _SpanKind.INTERNAL)
81+
if tracing_attributes is None:
82+
tracing_attributes = {}
83+
if kind is None:
84+
kind = _SpanKind.INTERNAL
6885

6986
def decorator(func: Callable[P, Awaitable[T]]) -> Callable[P, Awaitable[T]]:
7087
@functools.wraps(func)

sdk/core/corehttp/corehttp/runtime/policies/_authentication.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,22 @@ def send(self, request: PipelineRequest[HTTPRequestType]) -> PipelineResponse[HT
116116
self.on_request(request)
117117
try:
118118
response = self.next.send(request)
119-
self.on_response(request, response)
120119
except Exception: # pylint:disable=broad-except
121120
self.on_exception(request)
122121
raise
123-
else:
124-
if response.http_response.status_code == 401:
125-
self._token = None # any cached token is invalid
126-
if "WWW-Authenticate" in response.http_response.headers:
127-
request_authorized = self.on_challenge(request, response)
128-
if request_authorized:
129-
try:
130-
response = self.next.send(request)
131-
self.on_response(request, response)
132-
except Exception: # pylint:disable=broad-except
133-
self.on_exception(request)
134-
raise
122+
123+
self.on_response(request, response)
124+
if response.http_response.status_code == 401:
125+
self._token = None # any cached token is invalid
126+
if "WWW-Authenticate" in response.http_response.headers:
127+
request_authorized = self.on_challenge(request, response)
128+
if request_authorized:
129+
try:
130+
response = self.next.send(request)
131+
self.on_response(request, response)
132+
except Exception: # pylint:disable=broad-except
133+
self.on_exception(request)
134+
raise
135135

136136
return response
137137

sdk/core/corehttp/corehttp/runtime/policies/_authentication_async.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ async def send(
9191
except Exception: # pylint:disable=broad-except
9292
await await_result(self.on_exception, request)
9393
raise
94-
else:
95-
await await_result(self.on_response, request, response)
94+
await await_result(self.on_response, request, response)
9695

9796
if response.http_response.status_code == 401:
9897
self._token = None # any cached token is invalid
@@ -104,8 +103,7 @@ async def send(
104103
except Exception: # pylint:disable=broad-except
105104
await await_result(self.on_exception, request)
106105
raise
107-
else:
108-
await await_result(self.on_response, request, response)
106+
await await_result(self.on_response, request, response)
109107

110108
return response
111109

0 commit comments

Comments
 (0)