Skip to content

Commit

Permalink
useless-disable (Azure#39064)
Browse files Browse the repository at this point in the history
  • Loading branch information
l0lawrence authored Jan 8, 2025
1 parent a04b30b commit 90da0a6
Show file tree
Hide file tree
Showing 18 changed files with 24 additions and 25 deletions.
1 change: 0 additions & 1 deletion sdk/identity/azure-identity/azure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
# pylint:disable=missing-docstring
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_token(
attribute gives a reason. Any error response from Microsoft Entra ID is available as the error's
``response`` attribute.
"""
# pylint:disable=useless-super-delegation

return super(AuthorizationCodeCredential, self).get_token(
*scopes, claims=claims, tenant_id=tenant_id, client_secret=self._client_secret, **kwargs
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def _run_command(command: str, timeout: int) -> str:
# failed to execute 'cmd' or '/bin/sh'
error = CredentialUnavailableError(message="Failed to execute '{}'".format(args[0]))
raise error from ex
except Exception as ex: # pylint:disable=broad-except
except Exception as ex:
# could be a timeout, for example
error = CredentialUnavailableError(message="Failed to invoke the Azure Developer CLI")
raise error from ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _get_secret_key(response: PipelineResponse) -> str:
with open(key_file, "r", encoding="utf-8") as file:
try:
return file.read()
except Exception as error: # pylint:disable=broad-except
except Exception as error:
# user is expected to have obtained read permission prior to this being called
raise ClientAuthenticationError(
message="Could not read file {} contents: {}".format(key_file, error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def _run_command(command: str, timeout: int) -> str:
# failed to execute 'cmd' or '/bin/sh'
error = CredentialUnavailableError(message="Failed to execute '{}'".format(args[0]))
raise error from ex
except Exception as ex: # pylint:disable=broad-except
except Exception as ex:
# could be a timeout, for example
error = CredentialUnavailableError(message="Failed to invoke the Azure CLI")
raise error from ex
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def run_command_line(command_line: List[str], timeout: int) -> str:
proc = start_process(command_line)
stdout, stderr = proc.communicate(**kwargs)

except Exception as ex: # pylint:disable=broad-except
except Exception as ex:
# failed to execute "cmd" or "/bin/sh", or timed out; PowerShell and Az.Account may or may not be installed
# (handling Exception here because subprocess.SubprocessError and .TimeoutExpired were added in 3.3)
if proc and not proc.returncode:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _request_token(self, *scopes: str, **kwargs: Any) -> AccessTokenInfo:
# IMDS responded
_check_forbidden_response(ex)
self._endpoint_available = True
except Exception as ex: # pylint:disable=broad-except
except Exception as ex:
error_message = (
"ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint."
)
Expand Down Expand Up @@ -119,7 +119,7 @@ def _request_token(self, *scopes: str, **kwargs: Any) -> AccessTokenInfo:
raise ClientAuthenticationError(message=ex.message, response=ex.response) from ex
except json.decoder.JSONDecodeError as ex:
raise CredentialUnavailableError(message="ManagedIdentityCredential authentication unavailable.") from ex
except Exception as ex: # pylint:disable=broad-except
except Exception as ex:
# if anything else was raised, assume the endpoint is unavailable
error_message = "ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint."
raise CredentialUnavailableError(error_message) from ex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def do_GET(self):

self.wfile.write(b"Authentication complete. You can close this window.")

def log_message(self, format, *args): # pylint: disable=redefined-builtin,unused-argument
def log_message(self, format, *args): # pylint: disable=redefined-builtin
pass # this prevents server dumping messages to stdout


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def wrapper(*args, **kwargs):
except Exception as ex: # pylint: disable=broad-except
_LOGGER.debug("Failed to log the account information: %s", ex, exc_info=True)
return token
except Exception as ex: # pylint: disable=broad-except
except Exception as ex:
_LOGGER.log(
logging.DEBUG if within_credential_chain.get() else logging.WARNING,
"%s failed: %s",
Expand Down Expand Up @@ -70,7 +70,7 @@ def wrapper(*args, **kwargs):
return fn(*args, **kwargs)
except ClientAuthenticationError:
raise
except Exception as ex: # pylint:disable=broad-except
except Exception as ex:
auth_error = ClientAuthenticationError(message="Authentication failed: {}".format(ex))
raise auth_error from ex

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def _get_token_base(

# this may be the first authentication, or the user may have authenticated a different identity
self._auth_record = _build_auth_record(result)
except Exception as ex: # pylint:disable=broad-except
except Exception as ex:
_LOGGER.warning(
"%s.%s failed: %s",
self.__class__.__name__,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@


class ManagedIdentityClientBase(abc.ABC):
# pylint:disable=missing-client-constructor-parameter-credential
def __init__(
self,
request_factory: Callable[[str, dict], HttpRequest],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from azure.core.exceptions import ClientAuthenticationError
from azure.core.pipeline.policies import ContentDecodePolicy
from azure.core.pipeline.transport import ( # pylint:disable=unknown-option-value,no-legacy-azure-core-http-response-import
from azure.core.pipeline.transport import ( # pylint:disable=no-legacy-azure-core-http-response-import
HttpRequest,
HttpResponse,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def _request_token(self, *scopes: str, **kwargs: Any) -> AccessTokenInfo: # pyl
token_type=result.get("token_type", "Bearer"),
refresh_on=refresh_on,
)
error_desc = ""
if result and "error" in result:
error_desc = cast(str, result["error"])
error_message = self.get_unavailable_message(error_desc)
Expand Down Expand Up @@ -186,7 +187,7 @@ def _get_token_base(
exc_info=_LOGGER.isEnabledFor(logging.DEBUG),
)
raise ClientAuthenticationError(self.get_unavailable_message(str(ex))) from ex
except Exception as ex: # pylint:disable=broad-except
except Exception as ex:
_LOGGER.log(
logging.DEBUG if within_credential_chain.get() else logging.WARNING,
"%s.%s failed: %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __init__(
authority: Optional[str] = None,
tenant_id: Optional[str] = None,
**kwargs: Any
) -> None: # pylint:disable=unused-argument
) -> None:
self._authority = normalize_authority(authority) if authority else get_default_authority()
environment = urlparse(self._authority).netloc
self._environment_aliases = KNOWN_ALIASES.get(environment) or frozenset((environment,))
Expand Down Expand Up @@ -246,7 +246,7 @@ def _get_cached_access_token(
return AccessTokenInfo(
token["secret"], expires_on, token_type=token.get("token_type", "Bearer"), refresh_on=refresh_on
)
except Exception as ex: # pylint:disable=broad-except
except Exception as ex:
message = "Error accessing cached data: {}".format(ex)
raise CredentialUnavailableError(message=message) from ex

Expand All @@ -262,7 +262,7 @@ def _get_refresh_tokens(self, account, is_cae: bool = False) -> List[str]:
msal.TokenCache.CredentialType.REFRESH_TOKEN, query={"home_account_id": account["home_account_id"]}
)
return [token["secret"] for token in cache_entries if "secret" in token]
except Exception as ex: # pylint:disable=broad-except
except Exception as ex:
message = "Error accessing cached data: {}".format(ex)
raise CredentialUnavailableError(message=message) from ex

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class DefaultAzureCredential(ChainedTokenCredential):
:caption: Create a DefaultAzureCredential.
"""

def __init__(self, **kwargs: Any) -> None: # pylint: disable=too-many-statements, too-many-locals
def __init__(self, **kwargs: Any) -> None: # pylint: disable=too-many-statements
if "tenant_id" in kwargs:
raise TypeError("'tenant_id' is not supported in DefaultAzureCredential.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def close(self) -> None:
async def _acquire_token_silently(self, *scopes: str, **kwargs: Any) -> Optional[AccessTokenInfo]:
return self._client.get_cached_token(*scopes)

async def _request_token(self, *scopes: str, **kwargs: Any) -> AccessTokenInfo: # pylint:disable=unused-argument
async def _request_token(self, *scopes: str, **kwargs: Any) -> AccessTokenInfo:

if within_credential_chain.get() and not self._endpoint_available:
# If within a chain (e.g. DefaultAzureCredential), we do a quick check to see if the IMDS endpoint
Expand All @@ -49,7 +49,7 @@ async def _request_token(self, *scopes: str, **kwargs: Any) -> AccessTokenInfo:
# IMDS responded
_check_forbidden_response(ex)
self._endpoint_available = True
except Exception as ex: # pylint:disable=broad-except
except Exception as ex:
error_message = (
"ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint."
)
Expand Down Expand Up @@ -78,7 +78,7 @@ async def _request_token(self, *scopes: str, **kwargs: Any) -> AccessTokenInfo:
_check_forbidden_response(ex)
# any other error is unexpected
raise ClientAuthenticationError(message=ex.message, response=ex.response) from ex
except Exception as ex: # pylint:disable=broad-except
except Exception as ex:
# if anything else was raised, assume the endpoint is unavailable
error_message = "ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint."
raise CredentialUnavailableError(error_message) from ex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def wrapper(*args, **kwargs):
except Exception as ex: # pylint: disable=broad-except
_LOGGER.debug("Failed to log the account information: %s", ex, exc_info=True)
return token
except Exception as ex: # pylint: disable=broad-except
except Exception as ex:
_LOGGER.log(
logging.DEBUG if within_credential_chain.get() else logging.WARNING,
"%s failed: %s",
Expand Down Expand Up @@ -70,7 +70,7 @@ async def wrapper(*args, **kwargs):
return result
except ClientAuthenticationError:
raise
except Exception as ex: # pylint:disable=broad-except
except Exception as ex:
auth_error = ClientAuthenticationError(message="Authentication failed: {}".format(ex))
raise auth_error from ex

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
T = TypeVar("T", bound="AsyncManagedIdentityClient")


# pylint:disable=async-client-bad-name,missing-client-constructor-parameter-credential
# pylint:disable=async-client-bad-name
class AsyncManagedIdentityClient(AsyncContextManager, ManagedIdentityClientBase):
async def __aenter__(self: T) -> T:
await self._pipeline.__aenter__()
Expand Down

0 comments on commit 90da0a6

Please sign in to comment.