Skip to content

Commit df1106c

Browse files
authored
Fixed pylint issues for azure-communication-identity (Azure#39458)
* fixed next-pylint issues * fixed sdist failing tests * fixed mypy failure * applied the same changes to all shared folder * fixed lint issue * fixed PR comments * fixed sphinx failure for chat
1 parent 34c4350 commit df1106c

File tree

50 files changed

+184
-249
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+184
-249
lines changed

sdk/communication/azure-communication-callautomation/azure/communication/callautomation/_shared/auth_policy_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ def get_authentication_policy(
1919
credential: Union[TokenCredential, AsyncTokenCredential, AzureKeyCredential, str],
2020
decode_url: bool = False,
2121
is_async: bool = False,
22-
):
23-
# type: (...) -> Union[AsyncBearerTokenCredentialPolicy, BearerTokenCredentialPolicy, HMACCredentialsPolicy]
22+
) -> Union[AsyncBearerTokenCredentialPolicy, BearerTokenCredentialPolicy, HMACCredentialsPolicy]:
2423
"""Returns the correct authentication policy based on which credential is being passed.
2524
2625
:param endpoint: The endpoint to which we are authenticating to.

sdk/communication/azure-communication-callautomation/azure/communication/callautomation/_shared/policy.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ class HMACCredentialsPolicy(SansIOHTTPPolicy):
2626

2727
def __init__(
2828
self,
29-
host, # type: str
30-
access_key, # type: Union[str, AzureKeyCredential]
31-
decode_url=False, # type: bool
32-
):
33-
# type: (...) -> None
29+
host: str,
30+
access_key: Union[str, AzureKeyCredential],
31+
decode_url: bool = False,
32+
) -> None:
3433
super(HMACCredentialsPolicy, self).__init__()
3534

3635
if host.startswith("https://"):

sdk/communication/azure-communication-callautomation/azure/communication/callautomation/_shared/user_credential_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
6-
6+
# pylint: disable=C4763
77
from asyncio import Condition, Lock, Event
88
from datetime import timedelta
99
from typing import Any

sdk/communication/azure-communication-callautomation/azure/communication/callautomation/_shared/utils.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def _convert_datetime_to_utc_int(input_datetime) -> int:
2525
return int(calendar.timegm(input_datetime.utctimetuple()))
2626

2727

28-
def parse_connection_str(conn_str):
29-
# type: (Optional[str]) -> Tuple[str, str]
28+
def parse_connection_str(conn_str: Optional[str]) -> Tuple[str, str]:
3029
if conn_str is None:
3130
raise ValueError("Connection string is undefined.")
3231
endpoint = None
@@ -51,19 +50,16 @@ def parse_connection_str(conn_str):
5150
return host, str(shared_access_key)
5251

5352

54-
def get_current_utc_time():
55-
# type: () -> str
53+
def get_current_utc_time() -> str:
5654
return str(datetime.now(tz=TZ_UTC).strftime("%a, %d %b %Y %H:%M:%S ")) + "GMT"
5755

5856

59-
def get_current_utc_as_int():
60-
# type: () -> int
57+
def get_current_utc_as_int() -> int:
6158
current_utc_datetime = datetime.utcnow()
6259
return _convert_datetime_to_utc_int(current_utc_datetime)
6360

6461

65-
def create_access_token(token):
66-
# type: (str) -> AccessToken
62+
def create_access_token(token) -> AccessToken:
6763
"""Creates an instance of azure.core.credentials.AccessToken from a
6864
string token. The input string is jwt token in the following form:
6965
<token_header>.<token_payload>.<token_signature>

sdk/communication/azure-communication-callautomation/azure/communication/callautomation/_shared/utils_async.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# -------------------------------------------------------------------------
6-
7-
import asyncio
8-
6+
# pylint: disable=C4763
7+
from asyncio import sleep, ensure_future
98

109
class AsyncTimer:
1110
"""A non-blocking timer, that calls a function after a specified number of seconds:
@@ -19,10 +18,10 @@ def __init__(self, interval, callback):
1918
self._task = None
2019

2120
def start(self):
22-
self._task = asyncio.ensure_future(self._job())
21+
self._task = ensure_future(self._job())
2322

2423
async def _job(self):
25-
await asyncio.sleep(self._interval)
24+
await sleep(self._interval)
2625
await self._callback()
2726

2827
def cancel(self):

sdk/communication/azure-communication-chat/azure/communication/chat/_shared/auth_policy_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ def get_authentication_policy(
1919
credential: Union[TokenCredential, AsyncTokenCredential, AzureKeyCredential, str],
2020
decode_url: bool = False,
2121
is_async: bool = False,
22-
):
23-
# type: (...) -> Union[AsyncBearerTokenCredentialPolicy, BearerTokenCredentialPolicy, HMACCredentialsPolicy]
22+
) -> Union[AsyncBearerTokenCredentialPolicy, BearerTokenCredentialPolicy, HMACCredentialsPolicy]:
2423
"""Returns the correct authentication policy based on which credential is being passed.
2524
2625
:param endpoint: The endpoint to which we are authenticating to.

sdk/communication/azure-communication-chat/azure/communication/chat/_shared/policy.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ class HMACCredentialsPolicy(SansIOHTTPPolicy):
2626

2727
def __init__(
2828
self,
29-
host, # type: str
30-
access_key, # type: Union[str, AzureKeyCredential]
31-
decode_url=False, # type: bool
32-
):
33-
# type: (...) -> None
29+
host: str,
30+
access_key: Union[str, AzureKeyCredential],
31+
decode_url: bool = False,
32+
) -> None:
3433
super(HMACCredentialsPolicy, self).__init__()
3534

3635
if host.startswith("https://"):

sdk/communication/azure-communication-chat/azure/communication/chat/_shared/user_credential.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ class CommunicationTokenCredential(object):
1717
1818
:param str token: The token used to authenticate to an Azure Communication service.
1919
:keyword token_refresher: The sync token refresher to provide capacity to fetch a fresh token.
20-
The returned token must be valid (expiration date must be in the future).
20+
The returned token must be valid (expiration date must be in the future).
2121
:paramtype token_refresher: Callable[[], AccessToken]
2222
:keyword bool proactive_refresh: Whether to refresh the token proactively or not.
23-
If the proactive refreshing is enabled ('proactive_refresh' is true), the credential will use
24-
a background thread to attempt to refresh the token within 10 minutes before the cached token expires,
25-
the proactive refresh will request a new token by calling the 'token_refresher' callback.
26-
When 'proactive_refresh' is enabled, the Credential object must be either run within a context manager
27-
or the 'close' method must be called once the object usage has been finished.
23+
If the proactive refreshing is enabled ('proactive_refresh' is true), the credential will use
24+
a background thread to attempt to refresh the token within 10 minutes before the cached token expires,
25+
the proactive refresh will request a new token by calling the 'token_refresher' callback.
26+
When 'proactive_refresh' is enabled, the Credential object must be either run within a context manager
27+
or the 'close' method must be called once the object usage has been finished.
28+
2829
:raises: TypeError if paramater 'token' is not a string
2930
:raises: ValueError if the 'proactive_refresh' is enabled without providing the 'token_refresher' callable.
3031
"""

sdk/communication/azure-communication-chat/azure/communication/chat/_shared/user_credential_async.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
6-
6+
# pylint: disable=C4763
77
from asyncio import Condition, Lock, Event
88
from datetime import timedelta
99
from typing import Any
@@ -19,14 +19,15 @@ class CommunicationTokenCredential(object):
1919
2020
:param str token: The token used to authenticate to an Azure Communication service.
2121
:keyword token_refresher: The async token refresher to provide capacity to fetch a fresh token.
22-
The returned token must be valid (expiration date must be in the future).
22+
The returned token must be valid (expiration date must be in the future).
2323
:paramtype token_refresher: Callable[[], Awaitable[AccessToken]]
2424
:keyword bool proactive_refresh: Whether to refresh the token proactively or not.
25-
If the proactive refreshing is enabled ('proactive_refresh' is true), the credential will use
26-
a background thread to attempt to refresh the token within 10 minutes before the cached token expires,
27-
the proactive refresh will request a new token by calling the 'token_refresher' callback.
28-
When 'proactive_refresh is enabled', the Credential object must be either run within a context manager
29-
or the 'close' method must be called once the object usage has been finished.
25+
If the proactive refreshing is enabled ('proactive_refresh' is true), the credential will use
26+
a background thread to attempt to refresh the token within 10 minutes before the cached token expires,
27+
the proactive refresh will request a new token by calling the 'token_refresher' callback.
28+
When 'proactive_refresh is enabled', the Credential object must be either run within a context manager
29+
or the 'close' method must be called once the object usage has been finished.
30+
3031
:raises: TypeError if paramater 'token' is not a string
3132
:raises: ValueError if the 'proactive_refresh' is enabled without providing the 'token_refresher' function.
3233
"""
@@ -54,7 +55,6 @@ def __init__(self, token: str, **kwargs: Any):
5455
async def get_token(self, *scopes, **kwargs): # pylint: disable=unused-argument
5556
# type (*str, **Any) -> AccessToken
5657
"""The value of the configured token.
57-
5858
:param any scopes: Scopes to be added to the token.
5959
:return: AccessToken
6060
:rtype: ~azure.core.credentials.AccessToken

sdk/communication/azure-communication-chat/azure/communication/chat/_shared/utils.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def _convert_datetime_to_utc_int(input_datetime) -> int:
2525
return int(calendar.timegm(input_datetime.utctimetuple()))
2626

2727

28-
def parse_connection_str(conn_str):
29-
# type: (Optional[str]) -> Tuple[str, str]
28+
def parse_connection_str(conn_str: Optional[str]) -> Tuple[str, str]:
3029
if conn_str is None:
3130
raise ValueError("Connection string is undefined.")
3231
endpoint = None
@@ -51,19 +50,16 @@ def parse_connection_str(conn_str):
5150
return host, str(shared_access_key)
5251

5352

54-
def get_current_utc_time():
55-
# type: () -> str
53+
def get_current_utc_time() -> str:
5654
return str(datetime.now(tz=TZ_UTC).strftime("%a, %d %b %Y %H:%M:%S ")) + "GMT"
5755

5856

59-
def get_current_utc_as_int():
60-
# type: () -> int
57+
def get_current_utc_as_int() -> int:
6158
current_utc_datetime = datetime.utcnow()
6259
return _convert_datetime_to_utc_int(current_utc_datetime)
6360

6461

65-
def create_access_token(token):
66-
# type: (str) -> AccessToken
62+
def create_access_token(token) -> AccessToken:
6763
"""Creates an instance of azure.core.credentials.AccessToken from a
6864
string token. The input string is jwt token in the following form:
6965
<token_header>.<token_payload>.<token_signature>

0 commit comments

Comments
 (0)