Skip to content

Commit 44f1598

Browse files
committed
Format according to Python Style guides
1 parent 1778281 commit 44f1598

32 files changed

+1761
-1365
lines changed

firebase_admin/__init__.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,28 @@
1313
# limitations under the License.
1414

1515
"""Firebase Admin SDK for Python."""
16+
1617
import json
1718
import os
1819
import threading
19-
import typing
20+
from typing import Any, Dict, Optional, TypeVar, overload
2021

2122
from google.auth.credentials import Credentials as GoogleAuthCredentials
2223
from google.auth.exceptions import DefaultCredentialsError
2324
from firebase_admin import credentials
2425
from firebase_admin.__about__ import __version__
2526
from firebase_admin import _typing
2627

28+
__all__ = (
29+
'App',
30+
'delete_app',
31+
'get_app',
32+
'initialize_app',
33+
)
2734

28-
_T = typing.TypeVar('_T')
35+
_T = TypeVar('_T')
2936

30-
_apps: typing.Dict[str, 'App'] = {}
37+
_apps: Dict[str, 'App'] = {}
3138
_apps_lock = threading.RLock()
3239

3340
_DEFAULT_APP_NAME = '[DEFAULT]'
@@ -36,8 +43,8 @@
3643
'storageBucket']
3744

3845
def initialize_app(
39-
credential: typing.Optional[_typing.CredentialLike] = None,
40-
options: typing.Optional[typing.Dict[str, typing.Any]] = None,
46+
credential: Optional[_typing.CredentialLike] = None,
47+
options: Optional[Dict[str, Any]] = None,
4148
name: str = _DEFAULT_APP_NAME,
4249
) -> 'App':
4350
"""Initializes and returns a new App instance.
@@ -154,7 +161,7 @@ def get_app(name: str = _DEFAULT_APP_NAME) -> 'App':
154161
class _AppOptions:
155162
"""A collection of configuration options for an App."""
156163

157-
def __init__(self, options: typing.Optional[typing.Dict[str, typing.Any]]) -> None:
164+
def __init__(self, options: Optional[Dict[str, Any]]) -> None:
158165
if options is None:
159166
options = self._load_from_environment()
160167

@@ -163,16 +170,16 @@ def __init__(self, options: typing.Optional[typing.Dict[str, typing.Any]]) -> No
163170
'must be a dictionary.'.format(type(options)))
164171
self._options = options
165172

166-
@typing.overload
167-
def get(self, key: str, default: None = None) -> typing.Optional[typing.Any]: ...
173+
@overload
174+
def get(self, key: str, default: None = None) -> Optional[Any]: ...
168175
# possible issue: needs return Any | _T ?
169-
@typing.overload
176+
@overload
170177
def get(self, key: str, default: _T) -> _T: ...
171-
def get(self, key: str, default: typing.Any = None) -> typing.Optional[typing.Any]:
178+
def get(self, key: str, default: Any = None) -> Optional[Any]:
172179
"""Returns the option identified by the provided key."""
173180
return self._options.get(key, default)
174181

175-
def _load_from_environment(self) -> typing.Dict[str, typing.Any]:
182+
def _load_from_environment(self) -> Dict[str, Any]:
176183
"""Invoked when no options are passed to __init__, loads options from FIREBASE_CONFIG.
177184
178185
If the value of the FIREBASE_CONFIG environment variable starts with "{" an attempt is made
@@ -208,7 +215,7 @@ def __init__(
208215
self,
209216
name: str,
210217
credential: _typing.CredentialLike,
211-
options: typing.Optional[typing.Dict[str, typing.Any]],
218+
options: Optional[Dict[str, Any]],
212219
) -> None:
213220
"""Constructs a new App using the provided name and options.
214221
@@ -234,13 +241,13 @@ def __init__(
234241
'with a valid credential instance.')
235242
self._options = _AppOptions(options)
236243
self._lock = threading.RLock()
237-
self._services: typing.Optional[typing.Dict[str, typing.Any]] = {}
244+
self._services: Optional[Dict[str, Any]] = {}
238245

239246
App._validate_project_id(self._options.get('projectId'))
240247
self._project_id_initialized = False
241248

242249
@classmethod
243-
def _validate_project_id(cls, project_id: typing.Optional[str]) -> None:
250+
def _validate_project_id(cls, project_id: Optional[str]) -> None:
244251
if project_id is not None and not isinstance(project_id, str):
245252
raise ValueError(
246253
'Invalid project ID: "{0}". project ID must be a string.'.format(project_id))
@@ -258,13 +265,13 @@ def options(self) -> _AppOptions:
258265
return self._options
259266

260267
@property
261-
def project_id(self) -> typing.Optional[str]:
268+
def project_id(self) -> Optional[str]:
262269
if not self._project_id_initialized:
263270
self._project_id = self._lookup_project_id()
264271
self._project_id_initialized = True
265272
return self._project_id
266273

267-
def _lookup_project_id(self) -> typing.Optional[str]:
274+
def _lookup_project_id(self) -> Optional[str]:
268275
"""Looks up the Firebase project ID associated with an App.
269276
270277
If a ``projectId`` is specified in app options, it is returned. Then tries to
@@ -275,7 +282,7 @@ def _lookup_project_id(self) -> typing.Optional[str]:
275282
Returns:
276283
str: A project ID string or None.
277284
"""
278-
project_id: typing.Optional[str] = self._options.get('projectId')
285+
project_id: Optional[str] = self._options.get('projectId')
279286
if not project_id:
280287
try:
281288
project_id = getattr(self._credential, 'project_id')

0 commit comments

Comments
 (0)