Skip to content

Commit 358dc17

Browse files
author
cureprotocols
committed
fix(types): add type annotations to exceptions module for Mypy strict mode
1 parent 9f7d3fa commit 358dc17

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

google/auth/exceptions.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,23 @@
1414

1515
"""Exceptions used in the google.auth package."""
1616

17+
from typing import Any, Optional
18+
1719

1820
class GoogleAuthError(Exception):
19-
"""Base class for all google.auth errors."""
21+
"""Base class for all google.auth errors.
22+
23+
Args:
24+
retryable (bool): Indicates whether the error is retryable.
25+
"""
2026

21-
def __init__(self, *args, **kwargs):
22-
super(GoogleAuthError, self).__init__(*args)
23-
retryable = kwargs.get("retryable", False)
24-
self._retryable = retryable
27+
def __init__(self, *args: Any, **kwargs: Any) -> None:
28+
super().__init__(*args)
29+
self._retryable: bool = kwargs.get("retryable", False)
2530

2631
@property
27-
def retryable(self):
32+
def retryable(self) -> bool:
33+
"""Indicates whether the error is retryable."""
2834
return self._retryable
2935

3036

@@ -33,8 +39,7 @@ class TransportError(GoogleAuthError):
3339

3440

3541
class RefreshError(GoogleAuthError):
36-
"""Used to indicate that an refreshing the credentials' access token
37-
failed."""
42+
"""Used to indicate that refreshing the credentials' access token failed."""
3843

3944

4045
class UserAccessTokenError(GoogleAuthError):
@@ -46,30 +51,37 @@ class DefaultCredentialsError(GoogleAuthError):
4651

4752

4853
class MutualTLSChannelError(GoogleAuthError):
49-
"""Used to indicate that mutual TLS channel creation is failed, or mutual
50-
TLS channel credentials is missing or invalid."""
54+
"""Used to indicate that mutual TLS channel creation failed, or mutual
55+
TLS channel credentials are missing or invalid."""
56+
57+
@property
58+
def retryable(self) -> bool:
59+
"""Overrides retryable to always return False for this error."""
60+
return False
5161

5262

5363
class ClientCertError(GoogleAuthError):
5464
"""Used to indicate that client certificate is missing or invalid."""
5565

5666
@property
57-
def retryable(self):
67+
def retryable(self) -> bool:
68+
"""Overrides retryable to always return False for this error."""
5869
return False
5970

6071

6172
class OAuthError(GoogleAuthError):
62-
"""Used to indicate an error occurred during an OAuth related HTTP
63-
request."""
73+
"""Used to indicate an error occurred during an OAuth-related HTTP request."""
6474

6575

6676
class ReauthFailError(RefreshError):
67-
"""An exception for when reauth failed."""
77+
"""An exception for when reauth failed.
78+
79+
Args:
80+
message (str): Detailed error message.
81+
"""
6882

69-
def __init__(self, message=None, **kwargs):
70-
super(ReauthFailError, self).__init__(
71-
"Reauthentication failed. {0}".format(message), **kwargs
72-
)
83+
def __init__(self, message: Optional[str] = None, **kwargs: Any) -> None:
84+
super().__init__(f"Reauthentication failed. {message}", **kwargs)
7385

7486

7587
class ReauthSamlChallengeFailError(ReauthFailError):
@@ -97,7 +109,7 @@ class InvalidType(DefaultCredentialsError, TypeError):
97109

98110

99111
class OSError(DefaultCredentialsError, EnvironmentError):
100-
"""Used to wrap EnvironmentError(OSError after python3.3)."""
112+
"""Used to wrap EnvironmentError (OSError after Python 3.3)."""
101113

102114

103115
class TimeoutError(GoogleAuthError):

0 commit comments

Comments
 (0)