Skip to content

Commit db3e97b

Browse files
author
Alejandro Casanovas
committed
more type annotations
1 parent c304465 commit db3e97b

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

O365/connection.py

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import logging
33
import time
4-
from typing import Callable, Dict, List, Optional, Tuple, Union
4+
from typing import Callable, Dict, List, Optional, Union
55
from urllib.parse import parse_qs, urlparse
66

77
from msal import ConfidentialClientApplication, PublicClientApplication
@@ -34,9 +34,9 @@
3434

3535
log = logging.getLogger(__name__)
3636

37-
O365_API_VERSION = "v2.0"
38-
GRAPH_API_VERSION = "v1.0"
39-
OAUTH_REDIRECT_URL = "https://login.microsoftonline.com/common/oauth2/nativeclient"
37+
O365_API_VERSION: str = "v2.0"
38+
GRAPH_API_VERSION: str = "v1.0"
39+
OAUTH_REDIRECT_URL: str = "https://login.microsoftonline.com/common/oauth2/nativeclient"
4040

4141
RETRIES_STATUS_LIST = (
4242
429, # Status code for TooManyRequests
@@ -45,9 +45,9 @@
4545
503,
4646
504, # Server errors
4747
)
48-
RETRIES_BACKOFF_FACTOR = 0.5
48+
RETRIES_BACKOFF_FACTOR: float = 0.5
4949

50-
DEFAULT_SCOPES = {
50+
DEFAULT_SCOPES: dict[str, list[str]] = {
5151
# wrap any scope in a 1 element tuple to avoid prefixing
5252
"basic": ["User.Read"],
5353
"mailbox": ["Mail.Read"],
@@ -87,9 +87,9 @@ class Protocol:
8787
"""Base class for all protocols"""
8888

8989
# Override these in subclass
90-
_protocol_url = "not_defined" # Main url to request.
91-
_oauth_scope_prefix = "" # Prefix for scopes
92-
_oauth_scopes = {} # Dictionary of {scopes_name: [scope1, scope2]}
90+
_protocol_url: str = "not_defined" # Main url to request.
91+
_oauth_scope_prefix: str = "" # Prefix for scopes
92+
_oauth_scopes: dict[str, list[str]] = {} # Dictionary of {scopes_name: [scope1, scope2]}
9393

9494
def __init__(
9595
self,
@@ -144,7 +144,7 @@ def __init__(
144144
self.max_top_value: int = 500 # Max $top parameter value
145145

146146
#: The in use timezone. |br| **Type:** str
147-
self._timezone = None
147+
self._timezone: Optional[ZoneInfo] = None
148148

149149
if timezone:
150150
self.timezone = timezone # property setter will convert this timezone to ZoneInfo if a string is provided
@@ -256,7 +256,7 @@ class MSGraphProtocol(Protocol):
256256
_oauth_scope_prefix = "https://graph.microsoft.com/"
257257
_oauth_scopes = DEFAULT_SCOPES
258258

259-
def __init__(self, api_version="v1.0", default_resource=None, **kwargs):
259+
def __init__(self, api_version: str = "v1.0", default_resource: Optional[str] = None, **kwargs):
260260
"""Create a new Microsoft Graph protocol object
261261
262262
_protocol_url = 'https://graph.microsoft.com/'
@@ -307,7 +307,7 @@ class MSOffice365Protocol(Protocol):
307307
_oauth_scope_prefix = "https://outlook.office.com/"
308308
_oauth_scopes = DEFAULT_SCOPES
309309

310-
def __init__(self, api_version="v2.0", default_resource=None, **kwargs):
310+
def __init__(self, api_version: str = "v2.0", default_resource: Optional[str] = None, **kwargs):
311311
"""Create a new Office 365 protocol object
312312
313313
_protocol_url = 'https://outlook.office.com/api/'
@@ -362,7 +362,8 @@ class MSBusinessCentral365Protocol(Protocol):
362362
_protocol_scope_prefix = "https://api.businesscentral.dynamics.com/"
363363

364364
def __init__(
365-
self, api_version="v1.0", default_resource=None, environment=None, **kwargs
365+
self, api_version: str ="v1.0", default_resource: Optional[str] = None,
366+
environment: Optional[str] = None, **kwargs
366367
):
367368
"""Create a new Microsoft Graph protocol object
368369
@@ -421,7 +422,7 @@ class Connection:
421422

422423
def __init__(
423424
self,
424-
credentials: Tuple,
425+
credentials: tuple,
425426
*,
426427
proxy_server: Optional[str] = None,
427428
proxy_port: Optional[int] = 8080,
@@ -520,7 +521,7 @@ def __init__(
520521
)
521522

522523
#: The credentials for the connection. |br| **Type:** tuple
523-
self.auth: Tuple = credentials
524+
self.auth: tuple = credentials
524525
#: The tenant id. |br| **Type:** str
525526
self.tenant_id: str = tenant_id
526527

@@ -699,7 +700,7 @@ def msal_client(self) -> MsalClientApplication:
699700

700701
def get_authorization_url(
701702
self, requested_scopes: List[str], redirect_uri: Optional[str] = None, **kwargs
702-
) -> Tuple[str, dict]:
703+
) -> tuple[str, dict]:
703704
"""Initializes the oauth authorization flow, getting the
704705
authorization url that the user must approve.
705706

0 commit comments

Comments
 (0)