Skip to content

Commit ded8f4d

Browse files
committed
Update pyright settings and remove suppressions
1 parent 44f1598 commit ded8f4d

17 files changed

+72
-64
lines changed

firebase_admin/_auth_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def validate_timestamp(
306306
if isinstance(timestamp, bool):
307307
raise ValueError('Boolean value specified as timestamp.')
308308
try:
309-
timestamp_int = int(timestamp) # type: ignore[reportArgumentType, arg-type]
309+
timestamp_int = int(timestamp) # pyright: ignore[reportArgumentType]
310310
except TypeError:
311311
raise ValueError('Invalid type for timestamp value: {0}.'.format(timestamp))
312312
else:
@@ -385,7 +385,7 @@ def validate_custom_claims(custom_claims: Any, required: bool = False) -> Option
385385

386386
if not isinstance(parsed, dict):
387387
raise ValueError('Custom claims must be parseable as a JSON object.')
388-
invalid_claims = RESERVED_CLAIMS.intersection(set(parsed.keys())) # type: ignore[reportUnknownArgumentType]
388+
invalid_claims = RESERVED_CLAIMS.intersection(set(parsed.keys()))
389389
if len(invalid_claims) > 1:
390390
joined = ', '.join(sorted(invalid_claims))
391391
raise ValueError('Claims "{0}" are reserved, and must not be set.'.format(joined))
@@ -417,7 +417,7 @@ def build_update_mask(params: Dict[str, Any]) -> List[str]:
417417
mask: List[str] = []
418418
for key, value in params.items():
419419
if isinstance(value, dict):
420-
child_mask = build_update_mask(value) # type: ignore[reportUnknownArgumentType]
420+
child_mask = build_update_mask(value)
421421
for child in child_mask:
422422
mask.append('{0}.{1}'.format(key, child))
423423
else:

firebase_admin/_gapic_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def handle_platform_error_from_googleapiclient(
5353
return handle_googleapiclient_error(error)
5454

5555
content = error.content.decode()
56-
status_code = cast(int, error.resp.status) # type: ignore[reportUnknownMemberType]
56+
status_code = cast(int, error.resp.status)
5757
error_dict, message = _utils._parse_platform_error(content, status_code) # pylint: disable=protected-access
5858
http_response = _http_response_from_googleapiclient_error(error)
5959
exc = None
@@ -124,7 +124,7 @@ def handle_googleapiclient_error(
124124
cause=error)
125125

126126
if not code:
127-
code = _utils._http_status_to_error_code(error.resp.status) # pylint: disable=protected-access # type: ignore[reportUnknownMemberType]
127+
code = _utils._http_status_to_error_code(error.resp.status) # pylint: disable=protected-access
128128
if not message:
129129
message = str(error)
130130
if not http_response:
@@ -138,5 +138,5 @@ def _http_response_from_googleapiclient_error(error: googleapiclient.errors.Http
138138
"""Creates a requests HTTP Response object from the given googleapiclient error."""
139139
resp = requests.Response()
140140
resp.raw = io.BytesIO(error.content)
141-
resp.status_code = cast(int, error.resp.status) # type: ignore[reportUnknownMemberType]
141+
resp.status_code = cast(int, error.resp.status)
142142
return resp

firebase_admin/_http_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
if hasattr(retry.Retry.DEFAULT, 'allowed_methods'):
6464
_ANY_METHOD: Dict[str, Any] = {'allowed_methods': None}
6565
else:
66-
_ANY_METHOD = {'method_whitelist': None} # type: ignore[reportConstantRedefinition]
66+
_ANY_METHOD = {'method_whitelist': None} # pyright: ignore[reportConstantRedefinition]
6767

6868
# Default retry configuration: Retries once on low-level connection and socket read errors.
6969
# Retries up to 4 times on HTTP 500 and 503 errors, with exponential backoff. Returns the
@@ -168,7 +168,7 @@ class call this method to send HTTP requests out. Refer to
168168
kwargs['timeout'] = self.timeout
169169
kwargs.setdefault('headers', {}).update(METRICS_HEADERS)
170170
# possible issue: _session can be None
171-
resp = self._session.request(method, self.base_url + url, **kwargs) # type: ignore[reportOptionalMemberAccess]
171+
resp = self._session.request(method, self.base_url + url, **kwargs)
172172
resp.raise_for_status()
173173
return resp
174174

@@ -225,7 +225,7 @@ def apply_auth_headers(
225225
'Attempting to apply auth headers. Credential validity before: %s',
226226
self._credential.valid
227227
)
228-
self._credential.before_request( # type: ignore[reportUnknownMemberType]
228+
self._credential.before_request(
229229
auth_request, request.method, str(request.url), request.headers
230230
)
231231
logger.debug('Auth headers applied. Credential validity after: %s', self._credential.valid)
@@ -260,7 +260,7 @@ def auth_flow(self, request: httpx.Request) -> 'Generator[httpx.Request, httpx.R
260260
self._max_refresh_attempts
261261
)
262262
# Explicitly force a credentials refresh
263-
self._credential.refresh(auth_request) # type: ignore[reportUnknownMemberType]
263+
self._credential.refresh(auth_request)
264264
_credential_refresh_attempt += 1
265265
else:
266266
logger.debug(

firebase_admin/_sseclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class KeepAuthSession(google.auth.transport.requests.AuthorizedSession):
4343
"""A session that does not drop authentication on redirects between domains."""
4444

4545
def __init__(self, credential: Optional[google.auth.credentials.Credentials]) -> None:
46-
super(KeepAuthSession, self).__init__(credential) # type: ignore[reportUnknownMemberType]
46+
super(KeepAuthSession, self).__init__(credential)
4747

4848
def rebuild_auth(self, prepared_request: requests.PreparedRequest, response: requests.Response) -> None:
4949
pass

firebase_admin/_token_gen.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def from_credential(
145145
cls,
146146
google_cred: Union[google.oauth2.service_account.Credentials, credentials.Signing]
147147
) -> '_SigningProvider':
148-
return _SigningProvider(google_cred.signer, google_cred.signer_email) # type: ignore[reportUnknownMemberType]
148+
return _SigningProvider(google_cred.signer, google_cred.signer_email)
149149

150150
@classmethod
151151
def from_iam(
@@ -203,10 +203,10 @@ def _init_signing_provider(self) -> _SigningProvider:
203203
# Attempt to discover a service account email from the local Metadata service. Use it
204204
# with the IAM service to sign bytes.
205205
resp = self.request(url=METADATA_SERVICE_URL, headers={'Metadata-Flavor': 'Google'})
206-
if resp.status != 200: # type: ignore[reportUnknownMemberType]
206+
if resp.status != 200:
207207
raise ValueError(
208-
'Failed to contact the local metadata service: {0}.'.format(resp.data.decode())) # type: ignore[reportUnknownMemberType]
209-
service_account = cast(str, resp.data.decode()) # type: ignore[reportUnknownMemberType]
208+
'Failed to contact the local metadata service: {0}.'.format(resp.data.decode()))
209+
service_account = cast(str, resp.data.decode())
210210
return _SigningProvider.from_iam(self.request, google_cred, service_account)
211211

212212
@property
@@ -268,7 +268,7 @@ def create_custom_token(
268268

269269
header = {'alg': signing_provider.alg}
270270
try:
271-
return jwt.encode(signing_provider.signer, payload, header=header) # type: ignore[reportUnknownMemberType]
271+
return jwt.encode(signing_provider.signer, payload, header=header)
272272
except google.auth.exceptions.TransportError as error:
273273
msg = 'Failed to sign custom token. {0}'.format(error)
274274
raise TokenSignError(msg, error)
@@ -343,7 +343,8 @@ def __call__(
343343
) -> google.auth.transport.Response:
344344
timeout = timeout or self.timeout_seconds
345345
return self._delegate(
346-
url, method=method, body=body, headers=headers, timeout=timeout, **kwargs) # type: ignore[reportArgumentType]
346+
url, method=method, body=body, headers=headers,
347+
timeout=timeout, **kwargs) # pyright: ignore[reportArgumentType]
347348

348349

349350
class TokenVerifier:
@@ -497,14 +498,15 @@ def verify(
497498

498499
try:
499500
if emulated:
500-
verified_claims: Dict[str, Any] = payload
501+
verified_claims = payload
501502
else:
502-
verified_claims = google.oauth2.id_token.verify_token( # type: ignore[reportUnknownMemberType]
503+
verified_claims = google.oauth2.id_token.verify_token(
503504
token,
504505
request=request,
505506
audience=self.project_id,
506507
certs_url=self.cert_url,
507508
clock_skew_in_seconds=clock_skew_seconds)
509+
verified_claims = cast(Dict[str, Any], verified_claims)
508510
verified_claims['uid'] = verified_claims['sub']
509511
return verified_claims
510512
except google.auth.exceptions.TransportError as error:
@@ -519,8 +521,8 @@ def _decode_unverified(
519521
token: Union[bytes, str],
520522
) -> Tuple[Dict[str, str], Dict[str, Any]]:
521523
try:
522-
header = cast('Mapping[str, str]', jwt.decode_header(token)) # type: ignore[reportUnknownMemberType]
523-
payload = cast('Mapping[str, Any]', jwt.decode(token, verify=False)) # type: ignore[reportUnknownMemberType]
524+
header = cast('Mapping[str, str]', jwt.decode_header(token))
525+
payload = cast('Mapping[str, Any]', jwt.decode(token, verify=False))
524526
return dict(header), dict(payload)
525527
except ValueError as error:
526528
raise self._invalid_token_error(str(error), error)

firebase_admin/_user_mgt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def photo_url(self) -> Optional[str]:
519519
@property
520520
def provider_id(self) -> str:
521521
# possible issue: can providerId be `None`?
522-
return self._data.get('providerId') # type: ignore[reportReturnType]
522+
return self._data.get('providerId') # pyright: ignore[reportReturnType]
523523

524524

525525
class ActionCodeSettings:

firebase_admin/_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,10 @@ def handle_httpx_error(
326326

327327
err_type = _error_code_to_exception_type(code)
328328
# possible issue: FirebaseError needs accept httpx.Response?
329-
return err_type(message=message, cause=error, http_response=error.response) # type: ignore[reportArgumentType]
329+
return err_type(
330+
message=message, cause=error,
331+
http_response=error.response # pyright: ignore[reportArgumentType]
332+
)
330333

331334
return exceptions.UnknownError(
332335
message='Unknown error while making a remote service call: {0}'.format(error),

firebase_admin/credentials.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def get_access_token(self) -> AccessTokenInfo:
8181
AccessTokenInfo: An access token obtained using the credential.
8282
"""
8383
google_cred = self.get_credential()
84-
google_cred.refresh(_request) # type: ignore[reportUnknownMemberType]
84+
google_cred.refresh(_request)
8585
return AccessTokenInfo(google_cred.token, google_cred.expiry)
8686

8787
def get_credential(self) -> GoogleAuthCredentials:
@@ -138,15 +138,15 @@ def __init__(self, cert: Union[StrPath, Dict[str, Any]]) -> None:
138138
raise ValueError('Invalid service account certificate. Certificate must contain a '
139139
'"type" field set to "{0}".'.format(self._CREDENTIAL_TYPE))
140140
try:
141-
self._g_credential = service_account.Credentials.from_service_account_info( # type: ignore[reportUnknownMemberType]
141+
self._g_credential = service_account.Credentials.from_service_account_info(
142142
json_data, scopes=_scopes)
143143
except ValueError as error:
144144
raise ValueError('Failed to initialize a certificate credential. '
145145
'Caused by: "{0}"'.format(error))
146146

147147
@property
148148
def project_id(self) -> Optional[str]:
149-
return self._g_credential.project_id # type: ignore[reportUnknownMemberType]
149+
return self._g_credential.project_id
150150

151151
@property
152152
def signer(self) -> crypt.Signer:
@@ -174,7 +174,8 @@ def __init__(self) -> None:
174174
project_id() is called. See those methods for possible errors raised.
175175
"""
176176
super(ApplicationDefault, self).__init__()
177-
self._g_credential: Optional[GoogleAuthCredentials] = None # Will be lazily-loaded via _load_credential().
177+
# Will be lazily-loaded via _load_credential().
178+
self._g_credential: Optional[GoogleAuthCredentials] = None
178179
self._project_id: Optional[str]
179180

180181
def get_credential(self) -> GoogleAuthCredentials:
@@ -202,7 +203,7 @@ def project_id(self) -> Optional[str]:
202203

203204
def _load_credential(self) -> None:
204205
if not self._g_credential:
205-
self._g_credential, self._project_id = google.auth.default(scopes=_scopes) # type: ignore[reportUnknownMemberType]
206+
self._g_credential, self._project_id = google.auth.default(scopes=_scopes)
206207

207208

208209
class RefreshToken(Base):
@@ -240,20 +241,19 @@ def __init__(self, refresh_token: Union[StrPath, Dict[str, Any]]) -> None:
240241
if json_data.get('type') != self._CREDENTIAL_TYPE:
241242
raise ValueError('Invalid refresh token configuration. JSON must contain a '
242243
'"type" field set to "{0}".'.format(self._CREDENTIAL_TYPE))
243-
self._g_credential = credentials.Credentials.from_authorized_user_info( # type: ignore[reportUnknownMemberType]
244-
json_data, _scopes)
244+
self._g_credential = credentials.Credentials.from_authorized_user_info(json_data, _scopes)
245245

246246
@property
247247
def client_id(self) -> Optional[str]:
248-
return self._g_credential.client_id # type: ignore[reportUnknownMemberType]
248+
return self._g_credential.client_id
249249

250250
@property
251251
def client_secret(self) -> Optional[str]:
252-
return self._g_credential.client_secret # type: ignore[reportUnknownMemberType]
252+
return self._g_credential.client_secret
253253

254254
@property
255255
def refresh_token(self) -> Optional[str]:
256-
return self._g_credential.refresh_token # type: ignore[reportUnknownMemberType]
256+
return self._g_credential.refresh_token
257257

258258
def get_credential(self) -> GoogleAuthCredentials:
259259
"""Returns the underlying Google credential.

firebase_admin/db.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def child(self, path: Optional[str]) -> 'Reference':
255255
return Reference(client=self._client, path=full_path)
256256

257257
@overload
258-
def get( # type: ignore[reportOverlappingOverload]
258+
def get( # pyright: ignore[reportOverlappingOverload]
259259
self,
260260
etag: Literal[True],
261261
shallow: bool = False,
@@ -722,7 +722,7 @@ class _Sorter(Generic[_K, _V]):
722722
@overload
723723
def __init__(self, results: Dict[_K, _V], order_by: str) -> None: ...
724724
@overload
725-
def __init__(self: '_Sorter[int, _V]', results: List[_V], order_by: str) -> None: ... # type: ignore[reportInvalidTypeVarUse]
725+
def __init__(self: '_Sorter[int, _V]', results: List[_V], order_by: str) -> None: ... # pyright: ignore[reportInvalidTypeVarUse]
726726
def __init__(self, results: Union[Dict[_K, _V], List[_V]], order_by: str) -> None:
727727
if isinstance(results, dict):
728728
self.dict_input = True
@@ -825,9 +825,9 @@ def _compare(self, other: '_SortEntry') -> Literal[-1, 0, 1]:
825825
else:
826826
self_key, other_key = self.key, other.key
827827

828-
if self_key < other_key: # type: ignore[reportOperatorIssue]
828+
if self_key < other_key: # pyright: ignore[reportOperatorIssue]
829829
return -1
830-
if self_key > other_key: # type: ignore[reportOperatorIssue]
830+
if self_key > other_key: # pyright: ignore[reportOperatorIssue]
831831
return 1
832832

833833
return 0
@@ -844,7 +844,7 @@ def __gt__(self, other: '_SortEntry') -> bool:
844844
def __ge__(self, other: '_SortEntry') -> bool:
845845
return self._compare(other) >= 0
846846

847-
def __eq__(self, other: '_SortEntry') -> bool: # type: ignore[reportIncompatibleMethodOverride]
847+
def __eq__(self, other: '_SortEntry') -> bool: # pyright: ignore[reportIncompatibleMethodOverride]
848848
return self._compare(other) == 0
849849

850850

firebase_admin/firestore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
try:
2727
import google.cloud.firestore
2828
# firestore defines __all__ for safe import *
29-
from google.cloud.firestore import * # type: ignore[reportWildcardImportFromLibrary]
29+
from google.cloud.firestore import * # pyright: ignore[reportWildcardImportFromLibrary]
3030
from google.cloud.firestore_v1.base_client import DEFAULT_DATABASE
3131
except ImportError as error:
3232
raise ImportError('Failed to import the Cloud Firestore library for Python. Make sure '
3333
'to install the "google-cloud-firestore" module.') from error
3434

3535
__all__ = ['client']
36-
__all__.extend(google.cloud.firestore.__all__) # type: ignore[reportUnsupportedDunderAll]
36+
__all__.extend(google.cloud.firestore.__all__) # pyright: ignore[reportUnsupportedDunderAll]
3737

3838

3939
_FIRESTORE_ATTRIBUTE = '_firestore'

0 commit comments

Comments
 (0)