Skip to content

Commit c7bdc63

Browse files
committed
Lint changes to allow some files to be complient with newer pylint versions
1 parent 254500e commit c7bdc63

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

firebase_admin/_http_client_async.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def base_url(self):
9595
def timeout(self):
9696
return self._timeout
9797

98-
def parse_body(self, resp):
98+
async def parse_body(self, resp):
9999
raise NotImplementedError
100100

101101
async def request(self, method, url, **kwargs):
@@ -124,13 +124,13 @@ class call this method to send async HTTP requests out. Refer to
124124
resp = await self._session.request(method, self.base_url + url, **kwargs)
125125
wrapped_resp = _CombinedResponse(resp)
126126

127-
try:
128-
# Get response content from StreamReader before it is closed by error throw.
129-
resp_content = await wrapped_resp.content()
130-
resp.raise_for_status()
127+
# Get response content from StreamReader before it is closed by error throw.
128+
resp_content = await wrapped_resp.content()
131129

132130
# Catch response error and re-release it after appending response body needed to
133131
# determine the underlying reason for the error.
132+
try:
133+
resp.raise_for_status()
134134
except ClientResponseError as err:
135135
raise ClientResponseWithBodyError(
136136
err.request_info,
@@ -178,6 +178,6 @@ class ClientResponseWithBodyError(aiohttp.ClientResponseError):
178178
aiohttp request.
179179
"""
180180
def __init__(self, request_info, history, response, response_content):
181-
super(ClientResponseWithBodyError, self).__init__(request_info, history)
181+
super().__init__(request_info, history)
182182
self.response = response
183183
self.response_content = response_content

firebase_admin/credentials.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,28 @@ def __init__(self, cert: str) -> None:
103103
IOError: If the specified certificate file doesn't exist or cannot be read.
104104
ValueError: If the specified certificate is invalid.
105105
"""
106-
super(Certificate, self).__init__()
106+
super().__init__()
107107
if _is_file_path(cert):
108-
with open(cert) as json_file:
108+
with open(cert, encoding="utf-8") as json_file:
109109
json_data = json.load(json_file)
110110
elif isinstance(cert, dict):
111111
json_data = cert
112112
else:
113113
raise ValueError(
114-
'Invalid certificate argument: "{0}". Certificate argument must be a file path, '
115-
'or a dict containing the parsed file contents.'.format(cert))
114+
f'Invalid certificate argument: "{cert}". Certificate argument must be a file '
115+
'path, or a dict containing the parsed file contents.')
116116

117117
if json_data.get('type') != self._CREDENTIAL_TYPE:
118118
raise ValueError('Invalid service account certificate. Certificate must contain a '
119-
'"type" field set to "{0}".'.format(self._CREDENTIAL_TYPE))
119+
f'"type" field set to "{self._CREDENTIAL_TYPE}".')
120120
try:
121121
self._g_credential = service_account.Credentials.from_service_account_info(
122122
json_data, scopes=_scopes)
123123
self._g_credential_async = service_account_async.Credentials.from_service_account_info(
124124
json_data, scopes=_scopes)
125125
except ValueError as error:
126126
raise ValueError('Failed to initialize a certificate credential. '
127-
'Caused by: "{0}"'.format(error))
127+
f'Caused by: "{error}"') from error
128128

129129
@property
130130
def project_id(self) -> str:
@@ -162,7 +162,7 @@ def __init__(self) -> None:
162162
The credentials will be lazily initialized when get_credential(), get_credential_async()
163163
or project_id() is called. See those methods for possible errors raised.
164164
"""
165-
super(ApplicationDefault, self).__init__()
165+
super().__init__()
166166
self._g_credential = None # Will be lazily-loaded via _load_credential().
167167
self._g_credential_async = None # Will be lazily-loaded via _load_credential_async().
168168

@@ -229,20 +229,20 @@ def __init__(self, refresh_token: str) -> None:
229229
IOError: If the specified file doesn't exist or cannot be read.
230230
ValueError: If the refresh token configuration is invalid.
231231
"""
232-
super(RefreshToken, self).__init__()
232+
super().__init__()
233233
if _is_file_path(refresh_token):
234-
with open(refresh_token) as json_file:
234+
with open(refresh_token, encoding="utf-8") as json_file:
235235
json_data = json.load(json_file)
236236
elif isinstance(refresh_token, dict):
237237
json_data = refresh_token
238238
else:
239239
raise ValueError(
240-
'Invalid refresh token argument: "{0}". Refresh token argument must be a file '
241-
'path, or a dict containing the parsed file contents.'.format(refresh_token))
240+
f'Invalid refresh token argument: "{refresh_token}". Refresh token argument must be'
241+
' a file path, or a dict containing the parsed file contents.')
242242

243243
if json_data.get('type') != self._CREDENTIAL_TYPE:
244244
raise ValueError('Invalid refresh token configuration. JSON must contain a '
245-
'"type" field set to "{0}".'.format(self._CREDENTIAL_TYPE))
245+
f'"type" field set to "{self._CREDENTIAL_TYPE}".')
246246
self._g_credential = credentials.Credentials.from_authorized_user_info(json_data, _scopes)
247247
self._g_credential_async = credentials_async.Credentials.from_authorized_user_info(
248248
json_data,

firebase_admin/messaging_async.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@
6161
]
6262

6363
# pylint: disable=unsubscriptable-object
64-
# TODO:(/b)Remove false positive unsubscriptable-object lint warnings caused by type hints Optional type.
65-
# This is fixed in pylint 2.7.0 but this version introduces new lint rules and requires multiple
66-
# file changes.
64+
# TODO:(/b)Remove false positive unsubscriptable-object lint warnings caused by type hints Optional
65+
# type. This is fixed in pylint 2.7.0 but this version introduces new lint rules and requires
66+
# multiple file changes.
6767
def _get_messaging_service(app: Optional[App]) -> "_MessagingServiceAsync":
6868
return _utils.get_app_service(app, _MESSAGING_ATTRIBUTE, _MessagingServiceAsync)
6969

@@ -160,7 +160,7 @@ def __init__(self, app: App) -> None:
160160
self._fcm_url = _MessagingServiceAsync.FCM_URL.format(project_id)
161161
self._fcm_headers = {
162162
'X-GOOG-API-FORMAT-VERSION': '2',
163-
'X-FIREBASE-CLIENT': 'fire-admin-python/{0}'.format(firebase_admin.__version__),
163+
'X-FIREBASE-CLIENT': f'fire-admin-python/{firebase_admin.__version__}'
164164
}
165165
timeout = app.options.get('httpTimeout', DEFAULT_TIMEOUT_SECONDS)
166166
self._credential = app.credential.get_credential_async()
@@ -206,12 +206,12 @@ async def make_topic_management_request(self, tokens, topic, operation):
206206
if not isinstance(topic, str) or not topic:
207207
raise ValueError('Topic must be a non-empty string.')
208208
if not topic.startswith('/topics/'):
209-
topic = '/topics/{0}'.format(topic)
209+
topic = f'/topics/{topic}'
210210
data = {
211211
'to': topic,
212212
'registration_tokens': tokens,
213213
}
214-
url = '{0}/{1}'.format(_MessagingServiceAsync.IID_URL, operation)
214+
url = f'{_MessagingServiceAsync.IID_URL}/{operation}'
215215
try:
216216
resp = await self._client.body(
217217
'post',
@@ -252,10 +252,10 @@ def _handle_iid_error(self, error: ClientResponseWithBodyError) -> FirebaseError
252252
code = data.get('error')
253253
msg = None
254254
if code:
255-
msg = 'Error while calling the IID service: {0}'.format(code)
255+
msg = f'Error while calling the IID service: {code}'
256256
else:
257-
msg = 'Unexpected HTTP response with status: {0}; body: {1}'.format(
258-
error.response.status_code, error.response.content.decode())
257+
msg = (f'Unexpected HTTP response with status: {error.response.status_code}; '
258+
f'body: {error.response.content.decode()}')
259259

260260
return _utils.handle_requests_error(error, msg)
261261

tests/test_credentials.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_init_from_invalid_certificate(self, file_name, error):
6464
with pytest.raises(error):
6565
credentials.Certificate(testutils.resource_filename(file_name))
6666

67-
@pytest.mark.parametrize('arg', [None, 0, 1, True, False, list(), tuple(), dict()])
67+
@pytest.mark.parametrize('arg', [None, 0, 1, True, False, [], tuple(), {}])
6868
def test_invalid_args(self, arg):
6969
with pytest.raises(ValueError):
7070
credentials.Certificate(arg)
@@ -156,7 +156,7 @@ def test_init_from_invalid_file(self):
156156
credentials.RefreshToken(
157157
testutils.resource_filename('service_account.json'))
158158

159-
@pytest.mark.parametrize('arg', [None, 0, 1, True, False, list(), tuple(), dict()])
159+
@pytest.mark.parametrize('arg', [None, 0, 1, True, False, [], tuple(), {}])
160160
def test_invalid_args(self, arg):
161161
with pytest.raises(ValueError):
162162
credentials.RefreshToken(arg)

0 commit comments

Comments
 (0)