Skip to content

Commit ccb0e03

Browse files
authored
Fix some doc issues in core (#41322)
* Fix some doc issues in core * updates * updates * update * updates
1 parent a90a512 commit ccb0e03

18 files changed

+273
-48
lines changed

sdk/core/azure-core/azure/core/credentials.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ def get_token_info(self, *scopes: str, options: Optional[TokenRequestOptions] =
116116
...
117117

118118
def close(self) -> None:
119-
pass
119+
"""Close the credential, releasing any resources it holds.
120+
121+
:return: None
122+
:rtype: None
123+
"""
120124

121125

122126
TokenProvider = Union[TokenCredential, SupportsTokenInfo]
@@ -171,7 +175,7 @@ def update(self, key: str) -> None:
171175
to update long-lived clients.
172176
173177
:param str key: The key used to authenticate to an Azure service
174-
:raises: ValueError or TypeError
178+
:raises ValueError or TypeError: If the key is None, empty, or not a string.
175179
"""
176180
if not key:
177181
raise ValueError("The key used for updating can not be None or empty")

sdk/core/azure-core/azure/core/credentials_async.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ async def get_token(
3939
...
4040

4141
async def close(self) -> None:
42-
pass
42+
"""Close the credential, releasing any resources.
43+
44+
:return: None
45+
:rtype: None
46+
"""
4347

4448
async def __aexit__(
4549
self,
@@ -70,7 +74,11 @@ async def get_token_info(self, *scopes: str, options: Optional[TokenRequestOptio
7074
...
7175

7276
async def close(self) -> None:
73-
pass
77+
"""Close the credential, releasing any resources.
78+
79+
:return: None
80+
:rtype: None
81+
"""
7482

7583
async def __aexit__(
7684
self,

sdk/core/azure-core/azure/core/paging.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ def __iter__(self) -> Iterator[Iterator[ReturnType]]:
6969
return self
7070

7171
def __next__(self) -> Iterator[ReturnType]:
72+
"""Get the next page in the iterator.
73+
74+
:returns: An iterator of objects in the next page.
75+
:rtype: iterator[ReturnType]
76+
:raises StopIteration: If there are no more pages to return.
77+
:raises AzureError: If the request fails.
78+
"""
7279
if self.continuation_token is None and self._did_a_call_already:
7380
raise StopIteration("End of paging")
7481
try:
@@ -118,6 +125,12 @@ def __iter__(self) -> Iterator[ReturnType]:
118125
return self
119126

120127
def __next__(self) -> ReturnType:
128+
"""Get the next item in the iterator.
129+
130+
:returns: The next item in the iterator.
131+
:rtype: ReturnType
132+
:raises StopIteration: If there are no more items to return.
133+
"""
121134
if self._page_iterator is None:
122135
self._page_iterator = itertools.chain.from_iterable(self.by_page())
123136
return next(self._page_iterator)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,18 @@ def __delitem__(self, key: str) -> None:
107107
def clear( # pylint: disable=docstring-missing-return, docstring-missing-rtype
108108
self,
109109
) -> None:
110-
"""Context objects cannot be cleared.
110+
"""Clears the context objects.
111111
112-
:raises: TypeError
112+
:raises TypeError: If context objects cannot be cleared
113113
"""
114114
raise TypeError("Context objects cannot be cleared.")
115115

116116
def update( # pylint: disable=docstring-missing-return, docstring-missing-rtype, docstring-missing-param
117117
self, *args: Any, **kwargs: Any
118118
) -> None:
119-
"""Context objects cannot be updated.
119+
"""Updates the context objects.
120120
121-
:raises: TypeError
121+
:raises TypeError: If context objects cannot be updated
122122
"""
123123
raise TypeError("Context objects cannot be updated.")
124124

@@ -135,7 +135,7 @@ def pop(self, *args: Any) -> Any:
135135
:type args: str
136136
:return: The value for this key.
137137
:rtype: any
138-
:raises: ValueError If the key is in the protected list.
138+
:raises ValueError: If the key is in the protected list.
139139
"""
140140
if args and args[0] in self._protected:
141141
raise ValueError("Context value {} cannot be popped.".format(args[0]))

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ def __init__( # pylint: disable=unused-argument
268268
self._prefix = prefix + " " if prefix else ""
269269

270270
def on_request(self, request: PipelineRequest[HTTPRequestType]) -> None:
271+
"""Called before the policy sends a request.
272+
273+
:param request: The request to be modified before sending.
274+
:type request: ~azure.core.pipeline.PipelineRequest
275+
"""
271276
request.http_request.headers[self._name] = f"{self._prefix}{self._credential.key}"
272277

273278

@@ -290,6 +295,11 @@ def __init__(
290295
self._credential = credential
291296

292297
def on_request(self, request: PipelineRequest[HTTPRequestType]) -> None:
298+
"""Called before the policy sends a request.
299+
300+
:param request: The request to be modified before sending.
301+
:type request: ~azure.core.pipeline.PipelineRequest
302+
"""
293303
url = request.http_request.url
294304
query = request.http_request.query
295305
signature = self._credential.signature

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ def __init__(self, *, instrumentation_config: Optional[Mapping[str, Any]] = None
101101
self._instrumentation_config = instrumentation_config
102102

103103
def on_request(self, request: PipelineRequest[HTTPRequestType]) -> None:
104+
"""Starts a span for the network call.
105+
106+
:param request: The PipelineRequest object
107+
:type request: ~azure.core.pipeline.PipelineRequest
108+
"""
104109
ctxt = request.context.options
105110
try:
106111
tracing_options: TracingOptions = ctxt.pop("tracing_options", {})
@@ -161,8 +166,8 @@ def on_request(self, request: PipelineRequest[HTTPRequestType]) -> None:
161166
token = tracer._suppress_auto_http_instrumentation() # pylint: disable=protected-access
162167
request.context[self._SUPPRESSION_TOKEN] = token
163168

164-
except Exception as err: # pylint: disable=broad-except
165-
_LOGGER.warning("Unable to start network span: %s", err)
169+
except Exception: # pylint: disable=broad-except
170+
_LOGGER.warning("Unable to start network span.")
166171

167172
def end_span(
168173
self,
@@ -234,9 +239,21 @@ def on_response(
234239
request: PipelineRequest[HTTPRequestType],
235240
response: PipelineResponse[HTTPRequestType, HTTPResponseType],
236241
) -> None:
242+
"""Ends the span for the network call and updates its status.
243+
244+
:param request: The PipelineRequest object
245+
:type request: ~azure.core.pipeline.PipelineRequest
246+
:param response: The PipelineResponse object
247+
:type response: ~azure.core.pipeline.PipelineResponse
248+
"""
237249
self.end_span(request, response=response.http_response)
238250

239251
def on_exception(self, request: PipelineRequest[HTTPRequestType]) -> None:
252+
"""Ends the span for the network call and updates its status with exception info.
253+
254+
:param request: The PipelineRequest object
255+
:type request: ~azure.core.pipeline.PipelineRequest
256+
"""
240257
self.end_span(request, exc_info=sys.exc_info())
241258

242259
def _set_http_client_span_attributes(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
class RetryMode(str, Enum, metaclass=CaseInsensitiveEnumMeta):
6868
# pylint: disable=enum-must-be-uppercase
69+
"""Enum for retry modes."""
6970
Exponential = "exponential"
7071
Fixed = "fixed"
7172

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,14 +510,21 @@ def on_request( # pylint: disable=too-many-return-statements
510510
log_string += "\nNo body was attached to the request"
511511
logger.info(log_string)
512512

513-
except Exception as err: # pylint: disable=broad-except
514-
logger.warning("Failed to log request: %s", repr(err))
513+
except Exception: # pylint: disable=broad-except
514+
logger.warning("Failed to log request.")
515515

516516
def on_response(
517517
self,
518518
request: PipelineRequest[HTTPRequestType],
519519
response: PipelineResponse[HTTPRequestType, HTTPResponseType],
520520
) -> None:
521+
"""Logs HTTP response status and headers.
522+
523+
:param request: The PipelineRequest object.
524+
:type request: ~azure.core.pipeline.PipelineRequest
525+
:param response: The PipelineResponse object.
526+
:type response: ~azure.core.pipeline.PipelineResponse
527+
"""
521528
http_response = response.http_response
522529

523530
# Get logger in my context first (request has been retried)
@@ -545,8 +552,8 @@ def on_response(
545552
value = self._redact_header(res_header, value)
546553
log_string += "\n '{}': '{}'".format(res_header, value)
547554
logger.info(log_string)
548-
except Exception as err: # pylint: disable=broad-except
549-
logger.warning("Failed to log response: %s", repr(err))
555+
except Exception: # pylint: disable=broad-except
556+
logger.warning("Failed to log response.")
550557

551558

552559
class ContentDecodePolicy(SansIOHTTPPolicy[HTTPRequestType, HTTPResponseType]):
@@ -683,6 +690,11 @@ def deserialize_from_http_generics(
683690
return cls.deserialize_from_text(response.text(encoding), mime_type, response=response)
684691

685692
def on_request(self, request: PipelineRequest[HTTPRequestType]) -> None:
693+
"""Set the response encoding in the request context.
694+
695+
:param request: The PipelineRequest object.
696+
:type request: ~azure.core.pipeline.PipelineRequest
697+
"""
686698
options = request.context.options
687699
response_encoding = options.pop("response_encoding", self._response_encoding)
688700
if response_encoding:
@@ -743,6 +755,11 @@ def __init__(
743755
self.proxies = proxies
744756

745757
def on_request(self, request: PipelineRequest[HTTPRequestType]) -> None:
758+
"""Adds the proxy information to the request context.
759+
760+
:param request: The PipelineRequest object
761+
:type request: ~azure.core.pipeline.PipelineRequest
762+
"""
746763
ctxt = request.context.options
747764
if self.proxies and "proxies" not in ctxt:
748765
ctxt["proxies"] = self.proxies

sdk/core/azure-core/azure/core/pipeline/transport/_aiohttp.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ async def __aexit__(
141141
await self.close()
142142

143143
async def open(self):
144+
"""Opens the connection."""
144145
if self._has_been_opened and not self.session:
145146
raise ValueError(
146147
"HTTP transport has already been closed. "
@@ -438,7 +439,7 @@ async def __anext__(self):
438439
except aiohttp.client_exceptions.ClientPayloadError as err:
439440
# This is the case that server closes connection before we finish the reading. aiohttp library
440441
# raises ClientPayloadError.
441-
_LOGGER.warning("Incomplete download: %s", err)
442+
_LOGGER.warning("Incomplete download.")
442443
internal_response.close()
443444
raise IncompleteReadError(err, error=err) from err
444445
except aiohttp.client_exceptions.ClientResponseError as err:
@@ -448,7 +449,7 @@ async def __anext__(self):
448449
except aiohttp.client_exceptions.ClientError as err:
449450
raise ServiceRequestError(err, error=err) from err
450451
except Exception as err:
451-
_LOGGER.warning("Unable to stream download: %s", err)
452+
_LOGGER.warning("Unable to stream download.")
452453
internal_response.close()
453454
raise
454455

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ def __repr__(self) -> str:
507507

508508

509509
class HttpResponse(_HttpResponseBase):
510+
"""Represent a HTTP response."""
511+
510512
def stream_download(self, pipeline: Pipeline[HttpRequest, "HttpResponse"], **kwargs: Any) -> Iterator[bytes]:
511513
"""Generator for streaming request body data.
512514

0 commit comments

Comments
 (0)