Skip to content

Commit

Permalink
Fix typing
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Lavigne <lavigne958@gmail.com>
  • Loading branch information
lavigne958 committed Jul 23, 2024
1 parent 59ad8e4 commit c92df62
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions gspread/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ class FlowCallable(Protocol):

def __call__(
self, client_config: Mapping[str, Any], scopes: Iterable[str], port: int = 0
) -> Credentials: ...
) -> OAuthCredentials: ...


def local_server_flow(
client_config: Mapping[str, Any], scopes: Iterable[str], port: int = 0
) -> Credentials:
) -> OAuthCredentials:
"""Run an OAuth flow using a local server strategy.
Creates an OAuth flow and runs `google_auth_oauthlib.flow.InstalledAppFlow.run_local_server <https://google-auth-oauthlib.readthedocs.io/en/latest/reference/google_auth_oauthlib.flow.html#google_auth_oauthlib.flow.InstalledAppFlow.run_local_server>`_.
Expand All @@ -113,15 +113,15 @@ def local_server_flow(

def load_credentials(
filename: Path = DEFAULT_AUTHORIZED_USER_FILENAME,
) -> Optional[Credentials]:
) -> Optional[OAuthCredentials]:
if filename.exists():
return OAuthCredentials.from_authorized_user_file(filename)

return None


def store_credentials(
creds: Credentials,
creds: OAuthCredentials,
filename: Path = DEFAULT_AUTHORIZED_USER_FILENAME,
strip: str = "token",
) -> None:
Expand Down Expand Up @@ -204,7 +204,7 @@ def oauth(
authorized_user_filename = Path(authorized_user_filename)
creds = load_credentials(filename=authorized_user_filename)

if not isinstance(creds, Credentials):
if not isinstance(creds, OAuthCredentials):
with open(credentials_filename) as json_file:
client_config = json.load(json_file)
creds = flow(client_config=client_config, scopes=scopes)
Expand Down Expand Up @@ -282,13 +282,15 @@ def oauth_from_dict(
:rtype: (:class:`gspread.client.Client`, str)
"""

creds: Credentials = None
creds: Optional[OAuthCredentials] = None
if authorized_user_info is not None:
creds = OAuthCredentials.from_authorized_user_info(authorized_user_info, scopes)

if not creds and credentials is not None:
if creds is None and credentials is not None:
creds = flow(client_config=credentials, scopes=scopes)

assert creds is not None, "failed to initialize credentials"

client = Client(auth=creds, http_client=http_client)

# must return the creds to the user
Expand Down

0 comments on commit c92df62

Please sign in to comment.