diff --git a/sdk/communication/azure-communication-chat/azure/communication/chat/_communication_identifier_serializer.py b/sdk/communication/azure-communication-chat/azure/communication/chat/_communication_identifier_serializer.py index 6b08da1d07ea..188dbe85ec27 100644 --- a/sdk/communication/azure-communication-chat/azure/communication/chat/_communication_identifier_serializer.py +++ b/sdk/communication/azure-communication-chat/azure/communication/chat/_communication_identifier_serializer.py @@ -28,7 +28,7 @@ def serialize_identifier(identifier): :rtype: ~azure.communication.chat._generated.models.CommunicationIdentifierModel """ try: - request_model = {"raw_id": identifier.raw_id} + request_model: Dict[str, Any] = {"raw_id": identifier.raw_id} if identifier.kind and identifier.kind != CommunicationIdentifierKind.UNKNOWN: request_model[identifier.kind] = dict(identifier.properties) @@ -52,7 +52,7 @@ def deserialize_identifier(identifier_model): raw_id = identifier_model.raw_id if identifier_model.communication_user: - return CommunicationUserIdentifier(raw_id, raw_id=raw_id) + return CommunicationUserIdentifier(raw_id or "", raw_id=raw_id) if identifier_model.phone_number: return PhoneNumberIdentifier(identifier_model.phone_number.value, raw_id=raw_id) if identifier_model.microsoft_teams_user: @@ -62,4 +62,4 @@ def deserialize_identifier(identifier_model): is_anonymous=identifier_model.microsoft_teams_user.is_anonymous, cloud=identifier_model.microsoft_teams_user.cloud, ) - return UnknownIdentifier(raw_id) + return UnknownIdentifier(raw_id or "") diff --git a/sdk/communication/azure-communication-chat/azure/communication/chat/_utils.py b/sdk/communication/azure-communication-chat/azure/communication/chat/_utils.py index c4dc8b52b098..197e51ccd6de 100644 --- a/sdk/communication/azure-communication-chat/azure/communication/chat/_utils.py +++ b/sdk/communication/azure-communication-chat/azure/communication/chat/_utils.py @@ -4,6 +4,12 @@ # license information. # -------------------------------------------------------------------------- +from typing import List, Tuple, Dict, Optional, TYPE_CHECKING + +if TYPE_CHECKING: + from ._models import ChatParticipant + from ._generated.models import ChatError + def _to_utc_datetime(value): return value.strftime("%Y-%m-%dT%H:%M:%SZ") @@ -24,7 +30,7 @@ class CommunicationErrorResponseConverter(object): @classmethod def convert(cls, participants, chat_errors): - # type: (...) -> list[(ChatThreadParticipant, ChatError)] + # type: (List[ChatParticipant], Optional[List[ChatError]]) -> List[Tuple[Optional[ChatParticipant], ChatError]] """ Util function to convert AddChatParticipantsResult. @@ -41,12 +47,12 @@ def convert(cls, participants, chat_errors): """ def create_dict(participants): - # type: (...) -> Dict(str, ChatThreadParticipant) + # type: (List[ChatParticipant]) -> Dict[str, ChatParticipant] """ Create dictionary of id -> ChatParticipant - :param list participants: list of ChatThreadParticipant - :return: Dictionary of id -> ChatThreadParticipant + :param list participants: list of ChatParticipant + :return: Dictionary of id -> ChatParticipant :rtype: dict """ result = {} @@ -56,11 +62,13 @@ def create_dict(participants): _thread_participants_dict = create_dict(participants=participants) - failed_chat_thread_participants = [] + failed_chat_thread_participants: List[Tuple[Optional["ChatParticipant"], "ChatError"]] = [] if chat_errors is not None: for chat_error in chat_errors: - _thread_participant = _thread_participants_dict.get(chat_error.target) - failed_chat_thread_participants.append((_thread_participant, chat_error)) + target = chat_error.target + if target is not None: + _thread_participant = _thread_participants_dict.get(target) + failed_chat_thread_participants.append((_thread_participant, chat_error)) return failed_chat_thread_participants diff --git a/sdk/communication/azure-communication-chat/pyproject.toml b/sdk/communication/azure-communication-chat/pyproject.toml index 05ee5668ed6a..343877d67195 100644 --- a/sdk/communication/azure-communication-chat/pyproject.toml +++ b/sdk/communication/azure-communication-chat/pyproject.toml @@ -1,4 +1,4 @@ [tool.azure-sdk-build] -mypy = false +mypy = true pyright = false type_check_samples = false