Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Pylint warnings for the new checkers #26269

Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7a84f54
fixing lint issues
olena-stoliarova Sep 16, 2022
02e7819
Merge branch 'main' of https://github.com/ostoliarova-msft/azure-sdk-…
olena-stoliarova Sep 16, 2022
0fb4e07
fixing imports for phone numbers clients
olena-stoliarova Sep 16, 2022
a2b2897
regenerating sms and chat clients
olena-stoliarova Sep 27, 2022
b969f15
fixing failing tests
olena-stoliarova Sep 27, 2022
b0f3aa7
specifying exact commit for chat swagger
olena-stoliarova Sep 27, 2022
a5539f4
Merge branch 'main' of https://github.com/ostoliarova-msft/azure-sdk-…
olena-stoliarova Sep 30, 2022
e8f1fc3
making comments more precise and fixing pylint warnings for jobrouter
olena-stoliarova Sep 30, 2022
69c409c
fixing long lines in comments
olena-stoliarova Sep 30, 2022
bd4e29e
Merge branch 'main' of https://github.com/ostoliarova-msft/azure-sdk-…
olena-stoliarova Oct 5, 2022
ceef55f
regenerate chat with new autorest version
olena-stoliarova Oct 12, 2022
aca2c40
regenerate phonenumbers code with new autorest
olena-stoliarova Oct 12, 2022
52f94ad
Merge branch 'main' of https://github.com/ostoliarova-msft/azure-sdk-…
olena-stoliarova Oct 12, 2022
edd1bf3
Merge branch 'main' of https://github.com/ostoliarova-msft/azure-sdk-…
olena-stoliarova Oct 13, 2022
508267f
rollback changes for sms modality
olena-stoliarova Oct 17, 2022
0b3e3a5
rollback changes for sms modality
olena-stoliarova Oct 17, 2022
49913f3
rollback changes for sms modality
olena-stoliarova Oct 17, 2022
e3d64fe
add missing versions file
olena-stoliarova Oct 17, 2022
9417329
Merge branch 'main' of https://github.com/ostoliarova-msft/azure-sdk-…
olena-stoliarova Oct 17, 2022
4f27c29
move to correct directory
olena-stoliarova Oct 17, 2022
559bf7e
fixing lint error
olena-stoliarova Oct 17, 2022
31b5b8d
update changelogs
olena-stoliarova Oct 20, 2022
e548305
rollback chat changes
olena-stoliarova Oct 24, 2022
212e2e0
rollback chat changes
olena-stoliarova Oct 24, 2022
722b360
rollback chat changes
olena-stoliarova Oct 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/communication/azure-communication-chat/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- `CommunicationTokenCredential` exposes a new boolean keyword argument `proactive_refresh` that defaults to `False`. If set to `True`, the refreshing of the token will be scheduled in the background ensuring continuous authentication state.
- Added disposal function `close` for `CommunicationTokenCredential`.
- Added `identifier_from_raw_id` and ensured that `CommunicationIdentifier.raw_id` is populated on creation. Together, these can be used to translate between a `CommunicationIdentifier` and its underlying canonical raw ID representation. Developers can now use the raw ID as an encoded format for identifiers to store in their databases or as stable keys in general.
- Added the ability specify the API version by an optional `api_version` keyword parameter.

### Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------

from enum import Enum
from azure.core import CaseInsensitiveEnumMeta


class ApiVersion(str, Enum, metaclass=CaseInsensitiveEnumMeta):
V2021_09_07 = "2021-09-07"
ostoliarova-msft marked this conversation as resolved.
Show resolved Hide resolved


DEFAULT_VERSION = ApiVersion.V2021_09_07
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Union
from uuid import uuid4
from urllib.parse import urlparse

from azure.core.credentials import TokenCredential, AzureKeyCredential
from azure.core.tracing.decorator import distributed_trace
from azure.core.pipeline.policies import BearerTokenCredentialPolicy

from ._chat_thread_client import ChatThreadClient
from ._shared.user_credential import CommunicationTokenCredential
from ._generated import AzureCommunicationChatService
from ._generated.models import CreateChatThreadRequest
from ._models import (
Expand All @@ -24,24 +24,29 @@
CommunicationErrorResponseConverter
)
from ._version import SDK_MONIKER
from ._api_versions import DEFAULT_VERSION

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar, Union
from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar
from datetime import datetime
from azure.core.paging import ItemPaged


class ChatClient(object): # pylint: disable=client-accepts-api-version-keyword
class ChatClient(object):
"""A client to interact with the AzureCommunicationService Chat gateway.

This client provides operations to create chat thread, delete chat thread,
get chat thread client by thread id, list chat threads.

:param str endpoint:
The endpoint of the Azure Communication resource.
:param CommunicationTokenCredential credential:
The credentials with which to authenticate.
:param Union[TokenCredential, AzureKeyCredential] credential:
The credential we use to authenticate against the service.

:keyword api_version: Azure Communication Chat API version.
Default value is "2021-09-07". Note that overriding this default value may result in unsupported behavior.
:paramtype api_version: str

.. admonition:: Example:

Expand All @@ -56,7 +61,7 @@ class ChatClient(object): # pylint: disable=client-accepts-api-version-keyword
def __init__(
self,
endpoint, # type: str
credential, # type: CommunicationTokenCredential
credential: Union[TokenCredential, AzureKeyCredential],
ostoliarova-msft marked this conversation as resolved.
Show resolved Hide resolved
**kwargs # type: Any
):
# type: (...) -> None
Expand All @@ -74,10 +79,13 @@ def __init__(
raise ValueError("Invalid URL: {}".format(endpoint))

self._endpoint = endpoint
self._api_version = kwargs.pop("api_version", DEFAULT_VERSION)
self._credential = credential

self._client = AzureCommunicationChatService(
self._credential,
self._endpoint,
api_version=self._api_version,
authentication_policy=BearerTokenCredentialPolicy(self._credential),
sdk_moniker=SDK_MONIKER,
**kwargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Union

from urllib.parse import urlparse

from azure.core.credentials import TokenCredential, AzureKeyCredential
from azure.core.tracing.decorator import distributed_trace
from azure.core.pipeline.policies import BearerTokenCredentialPolicy

from ._shared.user_credential import CommunicationTokenCredential
from ._shared.models import CommunicationIdentifier
from ._generated import AzureCommunicationChatService
from ._generated.models import (
Expand All @@ -33,15 +33,16 @@
from ._communication_identifier_serializer import serialize_identifier
from ._utils import CommunicationErrorResponseConverter
from ._version import SDK_MONIKER
from ._api_versions import DEFAULT_VERSION

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar, Union, Tuple
from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar, Tuple
from datetime import datetime
from azure.core.paging import ItemPaged


class ChatThreadClient(object): # pylint: disable=client-accepts-api-version-keyword
class ChatThreadClient(object):
"""A client to interact with the AzureCommunicationService Chat gateway.
Instances of this class is normally retrieved by ChatClient.get_chat_thread_client()

Expand All @@ -54,12 +55,15 @@ class ChatThreadClient(object): # pylint: disable=client-accepts-api-version-key

:param str endpoint:
The endpoint of the Azure Communication resource.
:param CommunicationTokenCredential credential:
The credentials with which to authenticate. The value contains a User
Access Token
:param Union[TokenCredential, AzureKeyCredential] credential:
The credential we use to authenticate against the service.
:param str thread_id:
The unique thread id.

:keyword api_version: Azure Communication Chat API version.
Default value is "2021-09-07". Note that overriding this default value may result in unsupported behavior.
:paramtype api_version: str

.. admonition:: Example:

.. literalinclude:: ../samples/chat_thread_client_sample.py
Expand All @@ -73,7 +77,7 @@ class ChatThreadClient(object): # pylint: disable=client-accepts-api-version-key
def __init__(
self,
endpoint, # type: str
credential, # type: CommunicationTokenCredential
credential: Union[TokenCredential, AzureKeyCredential],
thread_id, # type: str
**kwargs # type: Any
):
Expand All @@ -96,10 +100,13 @@ def __init__(

self._thread_id = thread_id
self._endpoint = endpoint
self._api_version = kwargs.pop("api_version", DEFAULT_VERSION)
self._credential = credential

self._client = AzureCommunicationChatService(
endpoint,
self._credential,
self._endpoint,
api_version=self._api_version,
authentication_policy=BearerTokenCredentialPolicy(self._credential),
sdk_moniker=SDK_MONIKER,
**kwargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
# --------------------------------------------------------------------------

from ._azure_communication_chat_service import AzureCommunicationChatService
__all__ = ['AzureCommunicationChatService']

try:
from ._patch import patch_sdk # type: ignore
patch_sdk()
from ._patch import __all__ as _patch_all
from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import
except ImportError:
pass
_patch_all = []
from ._patch import patch_sdk as _patch_sdk

__all__ = ["AzureCommunicationChatService"]
__all__.extend([p for p in _patch_all if p not in __all__])

_patch_sdk()
Original file line number Diff line number Diff line change
Expand Up @@ -6,71 +6,72 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from typing import TYPE_CHECKING
from copy import deepcopy
from typing import Any

from azure.core import PipelineClient
from msrest import Deserializer, Serializer
from azure.core.credentials import AzureKeyCredential
from azure.core.rest import HttpRequest, HttpResponse

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any

from azure.core.pipeline.transport import HttpRequest, HttpResponse

from ._configuration import AzureCommunicationChatServiceConfiguration
from .operations import ChatThreadOperations
from .operations import ChatOperations
from . import models
from ._configuration import AzureCommunicationChatServiceConfiguration
from ._serialization import Deserializer, Serializer
from .operations import ChatOperations, ChatThreadOperations


class AzureCommunicationChatService(object):
class AzureCommunicationChatService: # pylint: disable=client-accepts-api-version-keyword
"""Azure Communication Chat Service.

:ivar chat_thread: ChatThreadOperations operations
:vartype chat_thread: azure.communication.chat.operations.ChatThreadOperations
:ivar chat: ChatOperations operations
:vartype chat: azure.communication.chat.operations.ChatOperations
:param endpoint: The endpoint of the Azure Communication resource.
:param credential: Credential needed for the client to connect to Azure. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential
:param endpoint: The endpoint of the Azure Communication resource. Required.
:type endpoint: str
:keyword api_version: Api Version. Default value is "2021-09-07". Note that overriding this
default value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(
self,
endpoint, # type: str
**kwargs # type: Any
):
# type: (...) -> None
base_url = '{endpoint}'
self._config = AzureCommunicationChatServiceConfiguration(endpoint, **kwargs)
self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs)
def __init__(self, credential: AzureKeyCredential, endpoint: str, **kwargs: Any) -> None:
_endpoint = "{endpoint}"
self._config = AzureCommunicationChatServiceConfiguration(credential=credential, endpoint=endpoint, **kwargs)
self._client = PipelineClient(base_url=_endpoint, config=self._config, **kwargs)

client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
self._serialize = Serializer(client_models)
self._serialize.client_side_validation = False
self._deserialize = Deserializer(client_models)
self._serialize.client_side_validation = False
self.chat_thread = ChatThreadOperations(self._client, self._config, self._serialize, self._deserialize)
self.chat = ChatOperations(self._client, self._config, self._serialize, self._deserialize)

self.chat_thread = ChatThreadOperations(
self._client, self._config, self._serialize, self._deserialize)
self.chat = ChatOperations(
self._client, self._config, self._serialize, self._deserialize)

def _send_request(self, http_request, **kwargs):
# type: (HttpRequest, Any) -> HttpResponse
def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
"""Runs the network request through the client's chained policies.

:param http_request: The network request you want to make. Required.
:type http_request: ~azure.core.pipeline.transport.HttpRequest
:keyword bool stream: Whether the response payload will be streamed. Defaults to True.
>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest("GET", "https://www.example.org/")
<HttpRequest [GET], url: 'https://www.example.org/'>
>>> response = client._send_request(request)
<HttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request

:param request: The network request you want to make. Required.
:type request: ~azure.core.rest.HttpRequest
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
:return: The response of your network call. Does not do error handling on your response.
:rtype: ~azure.core.pipeline.transport.HttpResponse
:rtype: ~azure.core.rest.HttpResponse
"""

request_copy = deepcopy(request)
path_format_arguments = {
'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
}
http_request.url = self._client.format_url(http_request.url, **path_format_arguments)
stream = kwargs.pop("stream", True)
pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs)
return pipeline_response.http_response

request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
return self._client.send_request(request_copy, **kwargs)

def close(self):
# type: () -> None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,57 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from typing import TYPE_CHECKING
from typing import Any

from azure.core.configuration import Configuration
from azure.core.credentials import AzureKeyCredential
from azure.core.pipeline import policies

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any

VERSION = "unknown"

class AzureCommunicationChatServiceConfiguration(Configuration):

class AzureCommunicationChatServiceConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
"""Configuration for AzureCommunicationChatService.

Note that all parameters used to create this instance are saved as instance
attributes.

:param endpoint: The endpoint of the Azure Communication resource.
:param credential: Credential needed for the client to connect to Azure. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential
:param endpoint: The endpoint of the Azure Communication resource. Required.
:type endpoint: str
:keyword api_version: Api Version. Default value is "2021-09-07". Note that overriding this
default value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(
self,
endpoint, # type: str
**kwargs # type: Any
):
# type: (...) -> None
def __init__(self, credential: AzureKeyCredential, endpoint: str, **kwargs: Any) -> None:
super(AzureCommunicationChatServiceConfiguration, self).__init__(**kwargs)
api_version = kwargs.pop("api_version", "2021-09-07") # type: str

if credential is None:
raise ValueError("Parameter 'credential' must not be None.")
if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")
super(AzureCommunicationChatServiceConfiguration, self).__init__(**kwargs)

self.credential = credential
self.endpoint = endpoint
self.api_version = "2021-09-07"
kwargs.setdefault('sdk_moniker', 'azurecommunicationchatservice/{}'.format(VERSION))
self.api_version = api_version
kwargs.setdefault("sdk_moniker", "azurecommunicationchatservice/{}".format(VERSION))
self._configure(**kwargs)

def _configure(
self,
**kwargs # type: Any
self, **kwargs # type: Any
):
# type: (...) -> None
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs)
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
self.http_logging_policy = kwargs.get('http_logging_policy') or policies.HttpLoggingPolicy(**kwargs)
self.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**kwargs)
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs)
self.authentication_policy = kwargs.get('authentication_policy')
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
self.authentication_policy = kwargs.get("authentication_policy")
if self.credential and not self.authentication_policy:
self.authentication_policy = policies.AzureKeyCredentialPolicy(self.credential, "Authorization", **kwargs)