Skip to content

Commit

Permalink
[Core] useless-supression fix for next-pylint (Azure#37263)
Browse files Browse the repository at this point in the history
* script

* core

* Revert "script"

This reverts commit f1506d3.

* remove

* update core

* black

* fix pylint

* black

* pylint

* ran black

* fix useless-disables

* no-member

* Revert "no-member"

This reverts commit 635013e.
  • Loading branch information
l0lawrence authored Sep 20, 2024
1 parent a9233f4 commit 79f436b
Show file tree
Hide file tree
Showing 57 changed files with 384 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def __enter__(self) -> "OpenTelemetrySpan":

self._current_ctxt_manager = trace.use_span(self._span_instance, end_on_exit=True)
if self._current_ctxt_manager:
self._current_ctxt_manager.__enter__() # pylint: disable=no-member
self._current_ctxt_manager.__enter__()
return self

def __exit__(self, exception_type, exception_value, traceback) -> None:
Expand All @@ -248,7 +248,7 @@ def __exit__(self, exception_type, exception_value, traceback) -> None:
error_type = f"{module}.{exception_type.__qualname__}" if module else exception_type.__qualname__
self.add_attribute(_ERROR_SPAN_ATTRIBUTE, error_type)
if self._current_ctxt_manager:
self._current_ctxt_manager.__exit__(exception_type, exception_value, traceback) # pylint: disable=no-member
self._current_ctxt_manager.__exit__(exception_type, exception_value, traceback)
self._current_ctxt_manager = None
for token in self._context_tokens:
context.detach(token)
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core/azure/core/_enum_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MyCustomEnum(str, Enum, metaclass=CaseInsensitiveEnumMeta):

def __getitem__(cls, name: str) -> Any:
# disabling pylint bc of pylint bug https://github.com/PyCQA/astroid/issues/713
return super(CaseInsensitiveEnumMeta, cls).__getitem__(name.upper()) # pylint: disable=no-value-for-parameter
return super(CaseInsensitiveEnumMeta, cls).__getitem__(name.upper())

def __getattr__(cls, name: str) -> Enum:
"""Return the enum member matching `name`.
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/azure-core/azure/core/_pipeline_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _build_pipeline(
[
config.logging_policy,
DistributedTracingPolicy(**kwargs),
SensitiveHeaderCleanupPolicy(**kwargs) if config.redirect_policy else None,
(SensitiveHeaderCleanupPolicy(**kwargs) if config.redirect_policy else None),
config.http_logging_policy or HttpLoggingPolicy(**kwargs),
]
)
Expand Down Expand Up @@ -195,7 +195,7 @@ def send_request(self, request: HTTPRequestType, *, stream: bool = False, **kwar
:rtype: ~azure.core.rest.HttpResponse
"""
return_pipeline_response = kwargs.pop("_return_pipeline_response", False)
pipeline_response = self._pipeline.run(request, stream=stream, **kwargs) # pylint: disable=protected-access
pipeline_response = self._pipeline.run(request, stream=stream, **kwargs)
if return_pipeline_response:
return pipeline_response # type: ignore # This is a private API we don't want to type in signature
return pipeline_response.http_response
8 changes: 5 additions & 3 deletions sdk/core/azure-core/azure/core/_pipeline_client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def __init__(
self._base_url = base_url
self._pipeline = pipeline or self._build_pipeline(self._config, **kwargs)

async def __aenter__(self) -> AsyncPipelineClient[HTTPRequestType, AsyncHTTPResponseType]:
async def __aenter__(
self,
) -> AsyncPipelineClient[HTTPRequestType, AsyncHTTPResponseType]:
await self._pipeline.__aenter__()
return self

Expand Down Expand Up @@ -223,7 +225,7 @@ def _build_pipeline(
[
config.logging_policy,
DistributedTracingPolicy(**kwargs),
SensitiveHeaderCleanupPolicy(**kwargs) if config.redirect_policy else None,
(SensitiveHeaderCleanupPolicy(**kwargs) if config.redirect_policy else None),
config.http_logging_policy or HttpLoggingPolicy(**kwargs),
]
)
Expand Down Expand Up @@ -263,7 +265,7 @@ def _build_pipeline(

async def _make_pipeline_call(self, request: HTTPRequestType, **kwargs) -> AsyncHTTPResponseType:
return_pipeline_response = kwargs.pop("_return_pipeline_response", False)
pipeline_response = await self._pipeline.run(request, **kwargs) # pylint: disable=protected-access
pipeline_response = await self._pipeline.run(request, **kwargs)
if return_pipeline_response:
return pipeline_response # type: ignore # This is a private API we don't want to type in signature
return pipeline_response.http_response
Expand Down
7 changes: 6 additions & 1 deletion sdk/core/azure-core/azure/core/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ class AccessTokenInfo:
"""Specifies the time, in Unix time, when the cached token should be proactively refreshed. Optional."""

def __init__(
self, token: str, expires_on: int, *, token_type: str = "Bearer", refresh_on: Optional[int] = None
self,
token: str,
expires_on: int,
*,
token_type: str = "Bearer",
refresh_on: Optional[int] = None,
) -> None:
self.token = token
self.expires_on = expires_on
Expand Down
18 changes: 13 additions & 5 deletions sdk/core/azure-core/azure/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def raise_with_traceback(exception: Callable, *args: Any, message: str = "", **k
exc_msg = "{}, {}: {}".format(message, exc_type.__name__, exc_value)
error = exception(exc_msg, *args, **kwargs)
try:
raise error.with_traceback(exc_traceback) # pylint: disable=raise-missing-from
raise error.with_traceback(exc_traceback)
except AttributeError: # Python 2
error.__traceback__ = exc_traceback
raise error # pylint: disable=raise-missing-from
Expand Down Expand Up @@ -150,7 +150,9 @@ def get(self, key: KeyType) -> Optional[ValueType]:


def map_error(
status_code: int, response: _HttpResponseCommonAPI, error_map: Mapping[int, Type[HttpResponseError]]
status_code: int,
response: _HttpResponseCommonAPI,
error_map: Mapping[int, Type[HttpResponseError]],
) -> None:
if not error_map:
return
Expand Down Expand Up @@ -309,7 +311,7 @@ def raise_with_traceback(self) -> None:
This method is deprecated as we don't support Python 2 anymore. Use raise/from instead.
"""
try:
raise super(AzureError, self).with_traceback(self.exc_traceback) # pylint: disable=raise-missing-from
raise super(AzureError, self).with_traceback(self.exc_traceback)
except AttributeError:
self.__traceback__: Optional[TracebackType] = self.exc_traceback
raise self # pylint: disable=raise-missing-from
Expand Down Expand Up @@ -355,7 +357,10 @@ class HttpResponseError(AzureError):
"""

def __init__(
self, message: Optional[object] = None, response: Optional[_HttpResponseCommonAPI] = None, **kwargs: Any
self,
message: Optional[object] = None,
response: Optional[_HttpResponseCommonAPI] = None,
**kwargs: Any,
) -> None:
# Don't want to document this one yet.
error_format = kwargs.get("error_format", ODataV4Format)
Expand Down Expand Up @@ -453,7 +458,10 @@ class TooManyRedirectsError(HttpResponseError, Generic[HTTPRequestType, HTTPResp
"""

def __init__(
self, history: "List[RequestHistory[HTTPRequestType, HTTPResponseType]]", *args: Any, **kwargs: Any
self,
history: "List[RequestHistory[HTTPRequestType, HTTPResponseType]]",
*args: Any,
**kwargs: Any,
) -> None:
self.history = history
message = "Reached maximum redirect attempts."
Expand Down
6 changes: 3 additions & 3 deletions sdk/core/azure-core/azure/core/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
DataType = TypeVar("DataType")


class CloudEvent(Generic[DataType]): # pylint:disable=too-many-instance-attributes
class CloudEvent(Generic[DataType]):
"""Properties of the CloudEvent 1.0 Schema.
All required parameters must be populated in order to send to Azure.
Expand Down Expand Up @@ -57,13 +57,13 @@ class CloudEvent(Generic[DataType]): # pylint:disable=too-many-instance-attribu
"""Identifies the context in which an event happened. The combination of id and source must
be unique for each distinct event. If publishing to a domain topic, source must be the domain topic name."""

type: str # pylint: disable=redefined-builtin
type: str
"""Type of event related to the originating occurrence."""

specversion: str = "1.0"
"""The version of the CloudEvent spec. Defaults to "1.0" """

id: str # pylint: disable=redefined-builtin
id: str
"""An identifier for the event. The combination of id and source must be
unique for each distinct event. If not provided, a random UUID will be generated and used."""

Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core/azure/core/paging.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#
# --------------------------------------------------------------------------
import itertools
from typing import ( # pylint: disable=unused-import
from typing import (
Callable,
Optional,
TypeVar,
Expand Down
21 changes: 16 additions & 5 deletions sdk/core/azure-core/azure/core/pipeline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@
#
# --------------------------------------------------------------------------

from typing import TypeVar, Generic, Dict, Any, Tuple, List, Optional, overload, TYPE_CHECKING, Union
from typing import (
TypeVar,
Generic,
Dict,
Any,
Tuple,
List,
Optional,
overload,
TYPE_CHECKING,
Union,
)

HTTPResponseType = TypeVar("HTTPResponseType", covariant=True) # pylint: disable=typevar-name-incorrect-variance
HTTPRequestType = TypeVar("HTTPRequestType", covariant=True) # pylint: disable=typevar-name-incorrect-variance
Expand All @@ -50,9 +61,7 @@ class PipelineContext(Dict[str, Any]):

_PICKLE_CONTEXT = {"deserialized_data"}

def __init__(
self, transport: Optional["TransportType"], **kwargs: Any
) -> None: # pylint: disable=super-init-not-called
def __init__(self, transport: Optional["TransportType"], **kwargs: Any) -> None:
self.transport: Optional["TransportType"] = transport
self.options = kwargs
self._protected = ["transport", "options"]
Expand Down Expand Up @@ -95,7 +104,9 @@ def __delitem__(self, key: str) -> None:
raise ValueError("Context value {} cannot be deleted.".format(key))
return super(PipelineContext, self).__delitem__(key)

def clear(self) -> None: # pylint: disable=docstring-missing-return, docstring-missing-rtype
def clear( # pylint: disable=docstring-missing-return, docstring-missing-rtype
self,
) -> None:
"""Context objects cannot be cleared.
:raises: TypeError
Expand Down
19 changes: 15 additions & 4 deletions sdk/core/azure-core/azure/core/pipeline/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@
# --------------------------------------------------------------------------
from __future__ import annotations
import logging
from typing import Generic, TypeVar, Union, Any, List, Dict, Optional, Iterable, ContextManager
from typing import (
Generic,
TypeVar,
Union,
Any,
List,
Dict,
Optional,
Iterable,
ContextManager,
)
from azure.core.pipeline import (
PipelineRequest,
PipelineResponse,
Expand Down Expand Up @@ -84,7 +94,7 @@ def send(self, request: PipelineRequest[HTTPRequestType]) -> PipelineResponse[HT
_await_result(self._policy.on_request, request)
try:
response = self.next.send(request)
except Exception: # pylint: disable=broad-except
except Exception:
_await_result(self._policy.on_exception, request)
raise
_await_result(self._policy.on_response, request, response)
Expand Down Expand Up @@ -146,7 +156,8 @@ def __init__(
policies: Optional[
Iterable[
Union[
HTTPPolicy[HTTPRequestType, HTTPResponseType], SansIOHTTPPolicy[HTTPRequestType, HTTPResponseType]
HTTPPolicy[HTTPRequestType, HTTPResponseType],
SansIOHTTPPolicy[HTTPRequestType, HTTPResponseType],
]
]
] = None,
Expand All @@ -168,7 +179,7 @@ def __enter__(self) -> Pipeline[HTTPRequestType, HTTPResponseType]:
self._transport.__enter__()
return self

def __exit__(self, *exc_details: Any) -> None: # pylint: disable=arguments-differ
def __exit__(self, *exc_details: Any) -> None:
self._transport.__exit__(*exc_details)

@staticmethod
Expand Down
30 changes: 20 additions & 10 deletions sdk/core/azure-core/azure/core/pipeline/_base_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@
# --------------------------------------------------------------------------
from __future__ import annotations
from types import TracebackType
from typing import Any, Union, Generic, TypeVar, List, Dict, Optional, Iterable, Type, AsyncContextManager
from typing import (
Any,
Union,
Generic,
TypeVar,
List,
Dict,
Optional,
Iterable,
Type,
AsyncContextManager,
)

from azure.core.pipeline import PipelineRequest, PipelineResponse, PipelineContext
from azure.core.pipeline.policies import AsyncHTTPPolicy, SansIOHTTPPolicy
Expand All @@ -37,9 +48,7 @@
HTTPRequestType = TypeVar("HTTPRequestType")


class _SansIOAsyncHTTPPolicyRunner(
AsyncHTTPPolicy[HTTPRequestType, AsyncHTTPResponseType]
): # pylint: disable=unsubscriptable-object
class _SansIOAsyncHTTPPolicyRunner(AsyncHTTPPolicy[HTTPRequestType, AsyncHTTPResponseType]):
"""Async implementation of the SansIO policy.
Modifies the request and sends to the next policy in the chain.
Expand All @@ -66,16 +75,14 @@ async def send(
response: PipelineResponse[HTTPRequestType, AsyncHTTPResponseType]
try:
response = await self.next.send(request)
except Exception: # pylint: disable=broad-except
except Exception:
await _await_result(self._policy.on_exception, request)
raise
await _await_result(self._policy.on_response, request, response)
return response


class _AsyncTransportRunner(
AsyncHTTPPolicy[HTTPRequestType, AsyncHTTPResponseType]
): # pylint: disable=unsubscriptable-object
class _AsyncTransportRunner(AsyncHTTPPolicy[HTTPRequestType, AsyncHTTPResponseType]):
"""Async Transport runner.
Uses specified HTTP transport type to send request and returns response.
Expand Down Expand Up @@ -106,7 +113,10 @@ async def send(
)


class AsyncPipeline(AsyncContextManager["AsyncPipeline"], Generic[HTTPRequestType, AsyncHTTPResponseType]):
class AsyncPipeline(
AsyncContextManager["AsyncPipeline"],
Generic[HTTPRequestType, AsyncHTTPResponseType],
):
"""Async pipeline implementation.
This is implemented as a context manager, that will activate the context
Expand All @@ -126,7 +136,7 @@ class AsyncPipeline(AsyncContextManager["AsyncPipeline"], Generic[HTTPRequestTyp
:caption: Builds the async pipeline for asynchronous transport.
"""

def __init__( # pylint: disable=super-init-not-called
def __init__(
self,
transport: AsyncHttpTransport[HTTPRequestType, AsyncHTTPResponseType],
policies: Optional[
Expand Down
4 changes: 3 additions & 1 deletion sdk/core/azure-core/azure/core/pipeline/_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def await_result(func: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> T:
return result


def is_rest(obj: object) -> TypeGuard[Union[HttpRequest, HttpResponse, AsyncHttpResponse]]:
def is_rest(
obj: object,
) -> TypeGuard[Union[HttpRequest, HttpResponse, AsyncHttpResponse]]:
"""Return whether a request or a response is a rest request / response.
Checking whether the response has the object content can sometimes result
Expand Down
Loading

0 comments on commit 79f436b

Please sign in to comment.