From b06fd169e4957a52b6972c7a5b1c5db00d1d30fa Mon Sep 17 00:00:00 2001 From: Sofia Robles Sandoval Date: Wed, 23 Jul 2025 15:04:18 -0600 Subject: [PATCH 01/10] Remove `mypy=false` and `type_check_samples=false` --- .../azure-communication-phonenumbers/pyproject.toml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sdk/communication/azure-communication-phonenumbers/pyproject.toml b/sdk/communication/azure-communication-phonenumbers/pyproject.toml index 05ee5668ed6a..f51cbbbb7407 100644 --- a/sdk/communication/azure-communication-phonenumbers/pyproject.toml +++ b/sdk/communication/azure-communication-phonenumbers/pyproject.toml @@ -1,4 +1,2 @@ [tool.azure-sdk-build] -mypy = false -pyright = false -type_check_samples = false +pyright = false \ No newline at end of file From 67d90ca5139ab4decfaacdcb59b7556043571880 Mon Sep 17 00:00:00 2001 From: Sofia Robles Sandoval Date: Wed, 23 Jul 2025 15:04:53 -0600 Subject: [PATCH 02/10] Enhance PhoneNumbersClient with type casting and improve error handling --- .../phonenumbers/_phone_numbers_client.py | 84 +++++++++++-------- .../aio/_phone_numbers_client_async.py | 38 +++++---- .../siprouting/_generated/aio/_patch.py | 3 + 3 files changed, 70 insertions(+), 55 deletions(-) diff --git a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_phone_numbers_client.py b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_phone_numbers_client.py index fb2d51067f80..60eef35cb8dc 100644 --- a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_phone_numbers_client.py +++ b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_phone_numbers_client.py @@ -5,7 +5,7 @@ # -------------------------------------------------------------------------- # pylint: disable=docstring-keyword-should-match-keyword-only -from typing import List, Optional, Union, Any +from typing import List, Optional, Union, Any, cast, Dict import uuid from azure.core.credentials import TokenCredential, AzureKeyCredential @@ -96,7 +96,7 @@ def from_connection_string(cls, conn_str: str, **kwargs: Any) -> "PhoneNumbersCl """ endpoint, access_key = parse_connection_str(conn_str) - return cls(endpoint, access_key, **kwargs) + return cls(endpoint, AzureKeyCredential(access_key), **kwargs) @distributed_trace def begin_purchase_phone_numbers( @@ -240,7 +240,9 @@ def begin_update_phone_number_capabilities( ) result_properties = poller.result().additional_properties - if "status" in result_properties and result_properties["status"].lower() == "failed": + if (result_properties is not None and + "status" in result_properties and + result_properties["status"].lower() == "failed"): raise HttpResponseError( message=result_properties["error"]["message"]) @@ -271,7 +273,8 @@ def list_purchased_phone_numbers(self, **kwargs: Any) -> ItemPaged[PurchasedPhon :returns: An iterator of purchased phone numbers. :rtype: ~azure.core.paging.ItemPaged[~azure.communication.phonenumbers.PurchasedPhoneNumber] """ - return self._phone_number_client.phone_numbers.list_phone_numbers(**kwargs) + return cast(ItemPaged[PurchasedPhoneNumber], + self._phone_number_client.phone_numbers.list_phone_numbers(**kwargs)) @distributed_trace def list_available_countries(self, **kwargs: Any) -> ItemPaged[PhoneNumberCountry]: @@ -287,9 +290,10 @@ def list_available_countries(self, **kwargs: Any) -> ItemPaged[PhoneNumberCountr ~azure.core.paging.ItemPaged[~azure.communication.phonenumbers.PhoneNumberCountry] :raises ~azure.core.exceptions.HttpResponseError: """ - return self._phone_number_client.phone_numbers.list_available_countries( - accept_language=self._accepted_language, **kwargs - ) + return cast(ItemPaged[PhoneNumberCountry], + self._phone_number_client.phone_numbers.list_available_countries( + accept_language=self._accepted_language, **kwargs + )) @distributed_trace def list_available_localities(self, country_code: str, **kwargs: Any) -> ItemPaged[PhoneNumberLocality]: @@ -310,13 +314,14 @@ def list_available_localities(self, country_code: str, **kwargs: Any) -> ItemPag ~azure.core.paging.ItemPaged[~azure.communication.phonenumbers.PhoneNumberLocality] :raises ~azure.core.exceptions.HttpResponseError: """ - return self._phone_number_client.phone_numbers.list_available_localities( - country_code, - administrative_division=kwargs.pop( - "administrative_division", None), - accept_language=self._accepted_language, - **kwargs - ) + return cast(ItemPaged[PhoneNumberLocality], + self._phone_number_client.phone_numbers.list_available_localities( + country_code, + administrative_division=kwargs.pop( + "administrative_division", None), + accept_language=self._accepted_language, + **kwargs + )) @distributed_trace def list_available_offerings(self, country_code: str, **kwargs: Any) -> ItemPaged[PhoneNumberOffering]: @@ -340,12 +345,13 @@ def list_available_offerings(self, country_code: str, **kwargs: Any) -> ItemPage ~azure.core.paging.ItemPaged[~azure.communication.phonenumbers.PhoneNumberOffering] :raises ~azure.core.exceptions.HttpResponseError: """ - return self._phone_number_client.phone_numbers.list_offerings( - country_code, - phone_number_type=kwargs.pop("phone_number_type", None), - assignment_type=kwargs.pop("assignment_type", None), - **kwargs - ) + return cast(ItemPaged[PhoneNumberOffering], + self._phone_number_client.phone_numbers.list_offerings( + country_code, + phone_number_type=kwargs.pop("phone_number_type", None), + assignment_type=kwargs.pop("assignment_type", None), + **kwargs + )) @distributed_trace def list_available_area_codes( @@ -374,15 +380,16 @@ def list_available_area_codes( :rtype: ~azure.core.paging.ItemPaged[~azure.communication.phonenumbers.PhoneNumberAreaCode] :raises ~azure.core.exceptions.HttpResponseError: """ - return self._phone_number_client.phone_numbers.list_area_codes( - country_code, - phone_number_type=phone_number_type, - assignment_type=kwargs.pop("assignment_type", None), - locality=kwargs.pop("locality", None), - administrative_division=kwargs.pop( - "administrative_division", None), - **kwargs - ) + return cast(ItemPaged[PhoneNumberAreaCode], + self._phone_number_client.phone_numbers.list_area_codes( + country_code, + phone_number_type=phone_number_type, + assignment_type=kwargs.pop("assignment_type", None), + locality=kwargs.pop("locality", None), + administrative_division=kwargs.pop( + "administrative_division", None), + **kwargs + )) @distributed_trace def search_operator_information( @@ -443,9 +450,10 @@ def list_reservations( # This allows mapping the generated model to the public model. # Internally, the generated client will create an instance of this iterator with each fetched page. - return self._phone_number_client.phone_numbers.list_reservations( - max_page_size=max_page_size, - **kwargs) + return cast(ItemPaged[PhoneNumbersReservation], + self._phone_number_client.phone_numbers.list_reservations( + max_page_size=max_page_size, + **kwargs)) @distributed_trace def create_or_update_reservation( @@ -481,15 +489,17 @@ def create_or_update_reservation( except ValueError as exc: raise ValueError("reservation_id must be in valid UUID format") from exc - phone_numbers = {} + phone_numbers: Dict[str, Optional[AvailablePhoneNumber]] = {} if numbers_to_add: for number in numbers_to_add: - phone_numbers[number.id] = number + if number.id is not None: + phone_numbers[number.id] = number if numbers_to_remove: - for number in numbers_to_remove: - phone_numbers[number] = None + for number_id in numbers_to_remove: + phone_numbers[number_id] = None - reservation = PhoneNumbersReservation(phone_numbers=phone_numbers) + # Cast to satisfy type checker - merge-patch operations allow None values + reservation = PhoneNumbersReservation(phone_numbers=cast(Optional[Dict[str, AvailablePhoneNumber]], phone_numbers)) return self._phone_number_client.phone_numbers.create_or_update_reservation( reservation_id, reservation, **kwargs) diff --git a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/aio/_phone_numbers_client_async.py b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/aio/_phone_numbers_client_async.py index baac0e9e416b..ff3b92076722 100644 --- a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/aio/_phone_numbers_client_async.py +++ b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/aio/_phone_numbers_client_async.py @@ -5,7 +5,7 @@ # -------------------------------------------------------------------------- # pylint: disable=docstring-keyword-should-match-keyword-only -from typing import List, Optional, Union, Any +from typing import List, Optional, Union, Any, cast, Dict import uuid from azure.core.credentials_async import AsyncTokenCredential @@ -99,7 +99,7 @@ def from_connection_string(cls, conn_str: str, **kwargs: Any) -> "PhoneNumbersCl """ endpoint, access_key = parse_connection_str(conn_str) - return cls(endpoint, access_key, **kwargs) + return cls(endpoint, AzureKeyCredential(access_key), **kwargs) @distributed_trace_async async def begin_purchase_phone_numbers( @@ -268,7 +268,7 @@ def list_purchased_phone_numbers(self, **kwargs: Any) -> AsyncItemPaged[Purchase ~azure.core.async_paging.AsyncItemPaged[~azure.communication.phonenumbers.PurchasedPhoneNumber] :raises ~azure.core.exceptions.HttpResponseError: """ - return self._phone_number_client.phone_numbers.list_phone_numbers(**kwargs) + return cast(AsyncItemPaged[PurchasedPhoneNumber], self._phone_number_client.phone_numbers.list_phone_numbers(**kwargs)) @distributed_trace def list_available_countries(self, **kwargs: Any) -> AsyncItemPaged[PhoneNumberCountry]: @@ -284,9 +284,9 @@ def list_available_countries(self, **kwargs: Any) -> AsyncItemPaged[PhoneNumberC ~azure.core.async_paging.AsyncItemPaged[~azure.communication.phonenumbers.PhoneNumberCountry] :raises ~azure.core.exceptions.HttpResponseError: """ - return self._phone_number_client.phone_numbers.list_available_countries( + return cast(AsyncItemPaged[PhoneNumberCountry], self._phone_number_client.phone_numbers.list_available_countries( accept_language=self._accepted_language, **kwargs - ) + )) @distributed_trace def list_available_localities(self, country_code: str, **kwargs: Any) -> AsyncItemPaged[PhoneNumberLocality]: @@ -307,13 +307,13 @@ def list_available_localities(self, country_code: str, **kwargs: Any) -> AsyncIt ~azure.core.async_paging.AsyncItemPaged[~azure.communication.phonenumbers.PhoneNumberLocality] :raises ~azure.core.exceptions.HttpResponseError: """ - return self._phone_number_client.phone_numbers.list_available_localities( + return cast(AsyncItemPaged[PhoneNumberLocality], self._phone_number_client.phone_numbers.list_available_localities( country_code, administrative_division=kwargs.pop( "administrative_division", None), accept_language=self._accepted_language, **kwargs - ) + )) @distributed_trace def list_available_offerings(self, country_code: str, **kwargs: Any) -> AsyncItemPaged[PhoneNumberOffering]: @@ -337,12 +337,12 @@ def list_available_offerings(self, country_code: str, **kwargs: Any) -> AsyncIte ~azure.core.async_paging.AsyncItemPaged[~azure.communication.phonenumbers.PhoneNumberOffering] :raises ~azure.core.exceptions.HttpResponseError: """ - return self._phone_number_client.phone_numbers.list_offerings( + return cast(AsyncItemPaged[PhoneNumberOffering], self._phone_number_client.phone_numbers.list_offerings( country_code, phone_number_type=kwargs.pop("phone_number_type", None), assignment_type=kwargs.pop("assignment_type", None), **kwargs - ) + )) @distributed_trace def list_available_area_codes( @@ -371,7 +371,7 @@ def list_available_area_codes( :rtype: ~azure.core.paging.ItemPaged[~azure.communication.phonenumbers.PhoneNumberAreaCode] :raises ~azure.core.exceptions.HttpResponseError: """ - return self._phone_number_client.phone_numbers.list_area_codes( + return cast(AsyncItemPaged[PhoneNumberAreaCode], self._phone_number_client.phone_numbers.list_area_codes( country_code, phone_number_type=phone_number_type, assignment_type=kwargs.pop("assignment_type", None), @@ -379,7 +379,7 @@ def list_available_area_codes( administrative_division=kwargs.pop( "administrative_division", None), **kwargs - ) + )) @distributed_trace_async async def search_operator_information( @@ -451,9 +451,9 @@ def list_reservations( ~azure.core.async_paging.AsyncItemPaged[~azure.communication.phonenumbers.PhoneNumbersReservation] """ - return self._phone_number_client.phone_numbers.list_reservations( + return cast(AsyncItemPaged[PhoneNumbersReservation], self._phone_number_client.phone_numbers.list_reservations( max_page_size=max_page_size, - **kwargs) + **kwargs)) @distributed_trace_async async def create_or_update_reservation( @@ -489,15 +489,17 @@ async def create_or_update_reservation( except ValueError as exc: raise ValueError("reservation_id must be in valid UUID format") from exc - phone_numbers = {} + phone_numbers: Dict[str, Optional[AvailablePhoneNumber]] = {} if numbers_to_add: for number in numbers_to_add: - phone_numbers[number.id] = number + if number.id is not None: + phone_numbers[number.id] = number if numbers_to_remove: - for number in numbers_to_remove: - phone_numbers[number] = None + for number_id in numbers_to_remove: + phone_numbers[number_id] = None - reservation = PhoneNumbersReservation(phone_numbers=phone_numbers) + # Cast to satisfy type checker - merge-patch operations allow None values + reservation = PhoneNumbersReservation(phone_numbers=cast(Optional[Dict[str, AvailablePhoneNumber]], phone_numbers)) return await self._phone_number_client.phone_numbers.create_or_update_reservation( reservation_id, reservation, **kwargs diff --git a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_generated/aio/_patch.py b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_generated/aio/_patch.py index 17dbc073e01b..472e4cca0a6b 100644 --- a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_generated/aio/_patch.py +++ b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_generated/aio/_patch.py @@ -26,6 +26,9 @@ # -------------------------------------------------------------------------- +__all__: list[str] = [] + + # This file is used for handwritten extensions to the generated code. Example: # https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md def patch_sdk(): From caf4828e90611a2f5c9f2448a92046fcfc658c38 Mon Sep 17 00:00:00 2001 From: Sofia Robles Sandoval Date: Wed, 23 Jul 2025 15:05:12 -0600 Subject: [PATCH 03/10] Enhance SipRoutingClient with additional type annotations and improve error handling for trunk retrieval --- .../siprouting/_generated/_patch.py | 3 ++ .../siprouting/_sip_routing_client.py | 46 +++++++++++++----- .../aio/_sip_routing_client_async.py | 48 ++++++++++++++----- 3 files changed, 74 insertions(+), 23 deletions(-) diff --git a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_generated/_patch.py b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_generated/_patch.py index 17dbc073e01b..04a7dde0a435 100644 --- a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_generated/_patch.py +++ b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_generated/_patch.py @@ -28,5 +28,8 @@ # This file is used for handwritten extensions to the generated code. Example: # https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md + +__all__: list[str] = [] + def patch_sdk(): pass diff --git a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_sip_routing_client.py b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_sip_routing_client.py index adcc74e1d191..a2a775fadc7c 100644 --- a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_sip_routing_client.py +++ b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_sip_routing_client.py @@ -4,11 +4,12 @@ # license information. # -------------------------------------------------------------------------- -from typing import TYPE_CHECKING, List, Any +from typing import TYPE_CHECKING, List, Any, Union, cast, Dict from urllib.parse import urlparse from azure.core.tracing.decorator import distributed_trace from azure.core.paging import ItemPaged +from azure.core.credentials import AzureKeyCredential from ._models import SipTrunk, SipTrunkRoute from ._generated.models import SipConfiguration, SipTrunkInternal, SipTrunkRouteInternal @@ -28,7 +29,7 @@ class SipRoutingClient(object): :param endpoint: The endpoint url for Azure Communication Service resource. :type endpoint: str :param credential: The credentials with which to authenticate. - :type credential: TokenCredential + :type credential: Union[TokenCredential, AzureKeyCredential, str] :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding this default value may result in unsupported behavior. :paramtype api_version: str @@ -36,7 +37,7 @@ class SipRoutingClient(object): def __init__( self, endpoint: str, - credential: "TokenCredential", + credential: Union["TokenCredential", AzureKeyCredential, str], **kwargs: Any ) -> None: @@ -93,6 +94,12 @@ def get_trunk( config = self._rest_service.sip_routing.get(**kwargs) + if config.trunks is None: + raise KeyError(f"Trunk with FQDN '{trunk_fqdn}' not found.") + + if trunk_fqdn not in config.trunks: + raise KeyError(f"Trunk with FQDN '{trunk_fqdn}' not found.") + trunk = config.trunks[trunk_fqdn] return SipTrunk(fqdn=trunk_fqdn, sip_signaling_port=trunk.sip_signaling_port) @@ -132,7 +139,10 @@ def delete_trunk( if trunk_fqdn is None: raise ValueError("Parameter 'trunk_fqdn' must not be None.") - self._rest_service.sip_routing.update(body=SipConfiguration(trunks={trunk_fqdn: None}), **kwargs) + # Note: The API accepts None values in the trunks dict to indicate deletion + # but the type annotation doesn't reflect this. We use cast to work around this. + trunks_dict = cast("Dict[str, SipTrunkInternal]", {trunk_fqdn: None}) + self._rest_service.sip_routing.update(body=SipConfiguration(trunks=trunks_dict), **kwargs) @distributed_trace def list_trunks( @@ -147,7 +157,10 @@ def list_trunks( """ def extract_data(config): - list_of_elem = [SipTrunk(fqdn=k, sip_signaling_port=v.sip_signaling_port) for k, v in config.trunks.items()] + if config.trunks is None: + list_of_elem = [] + else: + list_of_elem = [SipTrunk(fqdn=k, sip_signaling_port=v.sip_signaling_port) for k, v in config.trunks.items()] return None, list_of_elem # pylint: disable=unused-argument @@ -169,10 +182,13 @@ def list_routes( """ def extract_data(config): - list_of_elem = [ - SipTrunkRoute(description=x.description, name=x.name, number_pattern=x.number_pattern, trunks=x.trunks) - for x in config.routes - ] + if config.routes is None: + list_of_elem = [] + else: + list_of_elem = [ + SipTrunkRoute(description=x.description, name=x.name, number_pattern=x.number_pattern, trunks=x.trunks) + for x in config.routes + ] return None, list_of_elem # pylint: disable=unused-argument @@ -205,9 +221,13 @@ def set_trunks( for x in old_trunks: if x.fqdn not in [o.fqdn for o in trunks]: - config.trunks[x.fqdn] = None + if config.trunks is not None: + # Note: The API accepts None values in the trunks dict to indicate deletion + # but the type annotation doesn't reflect this. We use cast to work around this. + trunk_dict = cast(Dict[str, Any], config.trunks) + trunk_dict[x.fqdn] = None - if len(config.trunks) > 0: + if config.trunks is not None and len(config.trunks) > 0: self._rest_service.sip_routing.update(body=config, **kwargs) @distributed_trace @@ -237,6 +257,8 @@ def set_routes( def _list_trunks_(self, **kwargs: Any) -> List[SipTrunk]: config = self._rest_service.sip_routing.get(**kwargs) + if config.trunks is None: + return [] return [SipTrunk(fqdn=k, sip_signaling_port=v.sip_signaling_port) for k, v in config.trunks.items()] def _update_trunks_( @@ -248,6 +270,8 @@ def _update_trunks_( modified_config = SipConfiguration(trunks=trunks_internal) new_config = self._rest_service.sip_routing.update(body=modified_config, **kwargs) + if new_config.trunks is None: + return [] return [SipTrunk(fqdn=k, sip_signaling_port=v.sip_signaling_port) for k, v in new_config.trunks.items()] def close(self) -> None: diff --git a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/aio/_sip_routing_client_async.py b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/aio/_sip_routing_client_async.py index 4004f3dc469c..7732ad3b2e84 100644 --- a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/aio/_sip_routing_client_async.py +++ b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/aio/_sip_routing_client_async.py @@ -4,10 +4,11 @@ # license information. # -------------------------------------------------------------------------- -from typing import TYPE_CHECKING, List, Any +from typing import TYPE_CHECKING, List, Any, Union, cast, Dict from urllib.parse import urlparse from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.credentials import AzureKeyCredential from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async @@ -30,7 +31,7 @@ class SipRoutingClient(object): :param endpoint: The endpoint url for Azure Communication Service resource. :type endpoint: str :param credential: The credentials with which to authenticate. - :type credential: AsyncTokenCredential + :type credential: Union[AsyncTokenCredential, AzureKeyCredential, str] :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding this default value may result in unsupported behavior. :paramtype api_version: str @@ -39,7 +40,7 @@ class SipRoutingClient(object): def __init__( self, endpoint: str, - credential: "AsyncTokenCredential", + credential: Union["AsyncTokenCredential", AzureKeyCredential, str], **kwargs: Any ) -> None: @@ -98,6 +99,12 @@ async def get_trunk( config = await self._rest_service.sip_routing.get(**kwargs) + if config.trunks is None: + raise KeyError(f"Trunk with FQDN '{trunk_fqdn}' not found.") + + if trunk_fqdn not in config.trunks: + raise KeyError(f"Trunk with FQDN '{trunk_fqdn}' not found.") + trunk = config.trunks[trunk_fqdn] return SipTrunk(fqdn=trunk_fqdn, sip_signaling_port=trunk.sip_signaling_port) @@ -137,7 +144,10 @@ async def delete_trunk( if trunk_fqdn is None: raise ValueError("Parameter 'trunk_fqdn' must not be None.") - await self._rest_service.sip_routing.update(body=SipConfiguration(trunks={trunk_fqdn: None}), **kwargs) + # Note: The API accepts None values in the trunks dict to indicate deletion + # but the type annotation doesn't reflect this. We use cast to work around this. + trunks_dict = cast("Dict[str, SipTrunkInternal]", {trunk_fqdn: None}) + await self._rest_service.sip_routing.update(body=SipConfiguration(trunks=trunks_dict), **kwargs) @distributed_trace def list_trunks( @@ -152,7 +162,10 @@ def list_trunks( """ async def extract_data(config): - list_of_elem = [SipTrunk(fqdn=k, sip_signaling_port=v.sip_signaling_port) for k, v in config.trunks.items()] + if config.trunks is None: + list_of_elem = [] + else: + list_of_elem = [SipTrunk(fqdn=k, sip_signaling_port=v.sip_signaling_port) for k, v in config.trunks.items()] return None, AsyncList(list_of_elem) # pylint: disable=unused-argument @@ -174,10 +187,13 @@ def list_routes( """ async def extract_data(config): - list_of_elem = [ - SipTrunkRoute(description=x.description, name=x.name, number_pattern=x.number_pattern, trunks=x.trunks) - for x in config.routes - ] + if config.routes is None: + list_of_elem = [] + else: + list_of_elem = [ + SipTrunkRoute(description=x.description, name=x.name, number_pattern=x.number_pattern, trunks=x.trunks) + for x in config.routes + ] return None, AsyncList(list_of_elem) # pylint: disable=unused-argument @@ -210,9 +226,13 @@ async def set_trunks( for x in old_trunks: if x.fqdn not in [o.fqdn for o in trunks]: - config.trunks[x.fqdn] = None + if config.trunks is not None: + # Note: The API accepts None values in the trunks dict to indicate deletion + # but the type annotation doesn't reflect this. We use cast to work around this. + trunk_dict = cast(Dict[str, Any], config.trunks) + trunk_dict[x.fqdn] = None - if len(config.trunks) > 0: + if config.trunks is not None and len(config.trunks) > 0: await self._rest_service.sip_routing.update(body=config, **kwargs) @distributed_trace_async @@ -242,17 +262,21 @@ async def set_routes( async def _list_trunks_(self, **kwargs: Any): config = await self._rest_service.sip_routing.get(**kwargs) + if config.trunks is None: + return [] return [SipTrunk(fqdn=k, sip_signaling_port=v.sip_signaling_port) for k, v in config.trunks.items()] async def _update_trunks_( self, trunks: List[SipTrunk], **kwargs: Any - ) -> SipTrunk: + ) -> List[SipTrunk]: trunks_internal = {x.fqdn: SipTrunkInternal(sip_signaling_port=x.sip_signaling_port) for x in trunks} modified_config = SipConfiguration(trunks=trunks_internal) new_config = await self._rest_service.sip_routing.update(body=modified_config, **kwargs) + if new_config.trunks is None: + return [] return [SipTrunk(fqdn=k, sip_signaling_port=v.sip_signaling_port) for k, v in new_config.trunks.items()] async def close(self) -> None: From a77e6c31ff3e10becc53e3751fd638d2b78042d8 Mon Sep 17 00:00:00 2001 From: Sofia Robles Sandoval Date: Wed, 23 Jul 2025 15:05:52 -0600 Subject: [PATCH 04/10] Refactor environment variable access to use os.environ for consistency across samples --- .../browse_and_reserve_numbers_bulk_sample.py | 12 ++++++++---- .../browse_and_reserve_numbers_bulk_sample_async.py | 12 ++++++++---- .../browse_and_reserve_phone_numbers_sample.py | 12 ++++++++---- .../browse_and_reserve_phone_numbers_sample_async.py | 12 ++++++++---- .../samples/get_purchased_phone_number_sample.py | 4 ++-- .../get_purchased_phone_number_sample_async.py | 4 ++-- .../samples/list_purchased_phone_numbers_sample.py | 2 +- .../list_purchased_phone_numbers_sample_async.py | 2 +- .../managed_identity_authentication_sample.py | 2 +- .../samples/purchase_phone_number_sample.py | 4 ++-- .../samples/purchase_phone_number_sample_async.py | 4 ++-- .../samples/release_phone_number_sample.py | 4 ++-- .../samples/release_phone_number_sample_async.py | 4 ++-- .../samples/search_available_phone_numbers_sample.py | 2 +- .../search_available_phone_numbers_sample_async.py | 2 +- .../samples/siprouting/delete_sip_trunk_sample.py | 4 ++-- .../siprouting/delete_sip_trunk_sample_async.py | 4 ++-- .../samples/siprouting/get_sip_routes_sample.py | 2 +- .../siprouting/get_sip_routes_sample_async.py | 2 +- .../samples/siprouting/get_sip_trunk_sample.py | 4 ++-- .../samples/siprouting/get_sip_trunk_sample_async.py | 4 ++-- .../samples/siprouting/get_sip_trunks_sample.py | 2 +- .../siprouting/get_sip_trunks_sample_async.py | 2 +- .../samples/siprouting/set_sip_routes_sample.py | 2 +- .../siprouting/set_sip_routes_sample_async.py | 2 +- .../samples/siprouting/set_sip_trunk_sample.py | 6 +++--- .../samples/siprouting/set_sip_trunk_sample_async.py | 6 +++--- .../samples/siprouting/set_sip_trunks_sample.py | 6 +++--- .../siprouting/set_sip_trunks_sample_async.py | 6 +++--- .../update_phone_number_capabilities_sample.py | 4 ++-- .../update_phone_number_capabilities_sample_async.py | 4 ++-- 31 files changed, 79 insertions(+), 63 deletions(-) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample.py index 172a5fd5f166..a29fb7a9b5da 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample.py @@ -22,7 +22,7 @@ import uuid from azure.communication.phonenumbers import PhoneNumbersClient -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] phone_numbers_client = PhoneNumbersClient.from_connection_string( connection_str) @@ -49,13 +49,17 @@ def browse_and_reserve_numbers_bulk(): ) # Check if any errors occurred during reservation - numbers_with_error = [ - n for n in reservation.phone_numbers.values() if n.status == "error"] + numbers_with_error = [] + if reservation.phone_numbers: + numbers_with_error = [ + n for n in reservation.phone_numbers.values() if n.status == "error"] if any(numbers_with_error): print("Errors occurred during reservation:") for number in numbers_with_error: + error_code = number.error.code if number.error and number.error.code else "Unknown" + error_message = number.error.message if number.error and number.error.message else "Unknown error" print( - f"Phone number: {number.phone_number}, Error: {number.error.code}, Message: {number.error.message}") + f"Phone number: {number.phone_number}, Error: {error_code}, Message: {error_message}") else: print("Reservation operation completed without errors.") diff --git a/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample_async.py index ce0995aa392f..f6a37770e547 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample_async.py @@ -23,7 +23,7 @@ import uuid from azure.communication.phonenumbers.aio import PhoneNumbersClient -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] phone_numbers_client = PhoneNumbersClient.from_connection_string( connection_str) @@ -50,13 +50,17 @@ async def browse_and_reserve_numbers_bulk(): ) # Check if any errors occurred during reservation - numbers_with_error = [ - n for n in reservation.phone_numbers.values() if n.status == "error"] + numbers_with_error = [] + if reservation.phone_numbers: + numbers_with_error = [ + n for n in reservation.phone_numbers.values() if n.status == "error"] if any(numbers_with_error): print("Errors occurred during reservation:") for number in numbers_with_error: + error_code = number.error.code if number.error and number.error.code else "Unknown" + error_message = number.error.message if number.error and number.error.message else "Unknown error" print( - f"Phone number: {number.phone_number}, Error: {number.error.code}, Message: {number.error.message}") + f"Phone number: {number.phone_number}, Error: {error_code}, Message: {error_message}") else: print("Reservation operation completed without errors.") diff --git a/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample.py index 336c4bbdec6b..560e1569bc9e 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample.py @@ -22,7 +22,7 @@ import uuid from azure.communication.phonenumbers import PhoneNumbersClient -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] phone_numbers_client = PhoneNumbersClient.from_connection_string( connection_str) @@ -45,13 +45,17 @@ def browse_and_reserve_phone_numbers(): ) # Check if any errors occurred during reservation - numbers_with_error = [ - n for n in reservation.phone_numbers.values() if n.status == "error"] + numbers_with_error = [] + if reservation.phone_numbers: + numbers_with_error = [ + n for n in reservation.phone_numbers.values() if n.status == "error"] if any(numbers_with_error): print("Errors occurred during reservation:") for number in numbers_with_error: + error_code = number.error.code if number.error and number.error.code else "Unknown" + error_message = number.error.message if number.error and number.error.message else "Unknown error" print( - f"Phone number: {number.phone_number}, Error: {number.error.code}, Message: {number.error.message}") + f"Phone number: {number.phone_number}, Error: {error_code}, Message: {error_message}") else: print("Reservation operation completed without errors.") diff --git a/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample_async.py index d038b7449806..3e46f3aa4bf7 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample_async.py @@ -23,7 +23,7 @@ import uuid from azure.communication.phonenumbers.aio import PhoneNumbersClient -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] phone_numbers_client = PhoneNumbersClient.from_connection_string( connection_str) @@ -46,13 +46,17 @@ async def browse_and_reserve_phone_numbers(): ) # Check if any errors occurred during reservation - numbers_with_error = [ - n for n in reservation.phone_numbers.values() if n.status == "error"] + numbers_with_error = [] + if reservation.phone_numbers: + numbers_with_error = [ + n for n in reservation.phone_numbers.values() if n.status == "error"] if any(numbers_with_error): print("Errors occurred during reservation:") for number in numbers_with_error: + error_code = number.error.code if number.error and number.error.code else "Unknown" + error_message = number.error.message if number.error and number.error.message else "Unknown error" print( - f"Phone number: {number.phone_number}, Error: {number.error.code}, Message: {number.error.message}") + f"Phone number: {number.phone_number}, Error: {error_code}, Message: {error_message}") else: print("Reservation operation completed without errors.") diff --git a/sdk/communication/azure-communication-phonenumbers/samples/get_purchased_phone_number_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/get_purchased_phone_number_sample.py index ee5accf442d5..4d57dcfa5563 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/get_purchased_phone_number_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/get_purchased_phone_number_sample.py @@ -21,8 +21,8 @@ import os from azure.communication.phonenumbers import PhoneNumbersClient -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") -phone_number = os.getenv("AZURE_PHONE_NUMBER") # e.g. "+18001234567" +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] +phone_number = os.environ["AZURE_PHONE_NUMBER"] # e.g. "+18001234567" phone_numbers_client = PhoneNumbersClient.from_connection_string(connection_str) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/get_purchased_phone_number_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/get_purchased_phone_number_sample_async.py index 1d5cf6cbe1fe..2aec5e7c227d 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/get_purchased_phone_number_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/get_purchased_phone_number_sample_async.py @@ -22,8 +22,8 @@ import os from azure.communication.phonenumbers.aio import PhoneNumbersClient -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") -phone_number = os.getenv("AZURE_PHONE_NUMBER") # e.g. "+18001234567" +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] +phone_number = os.environ["AZURE_PHONE_NUMBER"] # e.g. "+18001234567" phone_numbers_client = PhoneNumbersClient.from_connection_string(connection_str) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/list_purchased_phone_numbers_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/list_purchased_phone_numbers_sample.py index d9e25d9f2b9f..be1a892de1f3 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/list_purchased_phone_numbers_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/list_purchased_phone_numbers_sample.py @@ -20,7 +20,7 @@ import os from azure.communication.phonenumbers import PhoneNumbersClient -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] phone_numbers_client = PhoneNumbersClient.from_connection_string(connection_str) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/list_purchased_phone_numbers_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/list_purchased_phone_numbers_sample_async.py index 606f8241bdd9..dce6df0af8a3 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/list_purchased_phone_numbers_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/list_purchased_phone_numbers_sample_async.py @@ -21,7 +21,7 @@ import os from azure.communication.phonenumbers.aio import PhoneNumbersClient -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] phone_numbers_client = PhoneNumbersClient.from_connection_string(connection_str) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/managed_identity_authentication_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/managed_identity_authentication_sample.py index 506083340554..205bef9b2240 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/managed_identity_authentication_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/managed_identity_authentication_sample.py @@ -24,7 +24,7 @@ from azure.communication.phonenumbers._shared.utils import parse_connection_str from azure.identity import DefaultAzureCredential -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] endpoint, _ = parse_connection_str(connection_str) phone_numbers_client = PhoneNumbersClient(endpoint, DefaultAzureCredential()) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/purchase_phone_number_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/purchase_phone_number_sample.py index 320383080756..debccf88b602 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/purchase_phone_number_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/purchase_phone_number_sample.py @@ -22,8 +22,8 @@ import os from azure.communication.phonenumbers import PhoneNumbersClient -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") -search_id = os.getenv("AZURE_COMMUNICATION_SERVICE_SEARCH_ID_TO_PURCHASE") +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] +search_id = os.environ["AZURE_COMMUNICATION_SERVICE_SEARCH_ID_TO_PURCHASE"] phone_numbers_client = PhoneNumbersClient.from_connection_string(connection_str) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/purchase_phone_number_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/purchase_phone_number_sample_async.py index 22a61e2eecb9..0228f0dcc139 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/purchase_phone_number_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/purchase_phone_number_sample_async.py @@ -23,8 +23,8 @@ import os from azure.communication.phonenumbers.aio import PhoneNumbersClient -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") -search_id = os.getenv("AZURE_COMMUNICATION_SERVICE_SEARCH_ID_TO_PURCHASE") +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] +search_id = os.environ["AZURE_COMMUNICATION_SERVICE_SEARCH_ID_TO_PURCHASE"] phone_numbers_client = PhoneNumbersClient.from_connection_string(connection_str) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/release_phone_number_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/release_phone_number_sample.py index 2cdd28b8aec2..9a7d31a080d9 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/release_phone_number_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/release_phone_number_sample.py @@ -21,8 +21,8 @@ import os from azure.communication.phonenumbers import PhoneNumbersClient -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") -phone_number_to_release = os.getenv("AZURE_PHONE_NUMBER_TO_RELEASE") # e.g. "+18001234567" +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] +phone_number_to_release = os.environ["AZURE_PHONE_NUMBER_TO_RELEASE"] # e.g. "+18001234567" phone_numbers_client = PhoneNumbersClient.from_connection_string(connection_str) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/release_phone_number_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/release_phone_number_sample_async.py index f031dc8ee1d7..160fafe7f610 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/release_phone_number_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/release_phone_number_sample_async.py @@ -22,8 +22,8 @@ import os from azure.communication.phonenumbers.aio import PhoneNumbersClient -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") -phone_number_to_release = os.getenv("AZURE_PHONE_NUMBER_TO_RELEASE") # e.g. "+18001234567" +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] +phone_number_to_release = os.environ["AZURE_PHONE_NUMBER_TO_RELEASE"] # e.g. "+18001234567" phone_numbers_client = PhoneNumbersClient.from_connection_string(connection_str) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/search_available_phone_numbers_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/search_available_phone_numbers_sample.py index d8b02dac69be..bfebf08c27d7 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/search_available_phone_numbers_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/search_available_phone_numbers_sample.py @@ -26,7 +26,7 @@ PhoneNumberCapabilityType, ) -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] phone_numbers_client = PhoneNumbersClient.from_connection_string(connection_str) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/search_available_phone_numbers_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/search_available_phone_numbers_sample_async.py index 829c5d7efabc..3fc291885095 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/search_available_phone_numbers_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/search_available_phone_numbers_sample_async.py @@ -27,7 +27,7 @@ PhoneNumberCapabilityType, ) -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] phone_numbers_client = PhoneNumbersClient.from_connection_string(connection_str) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/delete_sip_trunk_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/delete_sip_trunk_sample.py index 65faec66e44c..58084d6fc5e2 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/delete_sip_trunk_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/delete_sip_trunk_sample.py @@ -20,12 +20,12 @@ import os from azure.communication.phonenumbers.siprouting import SipRoutingClient -connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_string = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] client = SipRoutingClient.from_connection_string(connection_string) def delete_sip_trunk_sample(): - trunk_fqdn = os.getenv("COMMUNICATION_SAMPLES_TRUNK_FQDN") + trunk_fqdn = os.environ["COMMUNICATION_SAMPLES_TRUNK_FQDN"] client.delete_trunk(trunk_fqdn) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/delete_sip_trunk_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/delete_sip_trunk_sample_async.py index ac1ac9efcbc1..136707816085 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/delete_sip_trunk_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/delete_sip_trunk_sample_async.py @@ -21,12 +21,12 @@ import asyncio from azure.communication.phonenumbers.siprouting.aio import SipRoutingClient -connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_string = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] client = SipRoutingClient.from_connection_string(connection_string) async def delete_sip_trunk_sample(): - trunk_fqdn = os.getenv("COMMUNICATION_SAMPLES_TRUNK_FQDN") + trunk_fqdn = os.environ["COMMUNICATION_SAMPLES_TRUNK_FQDN"] async with client: await client.delete_trunk(trunk_fqdn) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_routes_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_routes_sample.py index b38e671fd2fe..3eaf1de0c836 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_routes_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_routes_sample.py @@ -19,7 +19,7 @@ import os from azure.communication.phonenumbers.siprouting import SipRoutingClient -connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_string = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] client = SipRoutingClient.from_connection_string(connection_string) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_routes_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_routes_sample_async.py index 53229e227be5..3771a26ec657 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_routes_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_routes_sample_async.py @@ -20,7 +20,7 @@ import asyncio from azure.communication.phonenumbers.siprouting.aio import SipRoutingClient -connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_string = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] client = SipRoutingClient.from_connection_string(connection_string) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_trunk_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_trunk_sample.py index 7d6be24d1b92..e46877c04fdd 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_trunk_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_trunk_sample.py @@ -20,12 +20,12 @@ import os from azure.communication.phonenumbers.siprouting import SipRoutingClient -connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_string = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] client = SipRoutingClient.from_connection_string(connection_string) def get_sip_trunk_sample(): - trunk_fqdn = os.getenv("COMMUNICATION_SAMPLES_TRUNK_FQDN") + trunk_fqdn = os.environ["COMMUNICATION_SAMPLES_TRUNK_FQDN"] try: sip_trunk = client.get_trunk(trunk_fqdn) print(sip_trunk.fqdn) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_trunk_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_trunk_sample_async.py index 91de0e05fa80..3c33e46eb513 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_trunk_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_trunk_sample_async.py @@ -21,12 +21,12 @@ import asyncio from azure.communication.phonenumbers.siprouting.aio import SipRoutingClient -connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_string = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] client = SipRoutingClient.from_connection_string(connection_string) async def get_sip_trunk_sample(): - trunk_fqdn = os.getenv("COMMUNICATION_SAMPLES_TRUNK_FQDN") + trunk_fqdn = os.environ["COMMUNICATION_SAMPLES_TRUNK_FQDN"] try: async with client: sip_trunk = await client.get_trunk(trunk_fqdn) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_trunks_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_trunks_sample.py index ce7030b9e9fd..87a5d96ccdb0 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_trunks_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_trunks_sample.py @@ -19,7 +19,7 @@ import os from azure.communication.phonenumbers.siprouting import SipRoutingClient -connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_string = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] client = SipRoutingClient.from_connection_string(connection_string) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_trunks_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_trunks_sample_async.py index 54c5fbdad0fa..20bb47de6801 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_trunks_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/get_sip_trunks_sample_async.py @@ -20,7 +20,7 @@ import asyncio from azure.communication.phonenumbers.siprouting.aio import SipRoutingClient -connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_string = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] client = SipRoutingClient.from_connection_string(connection_string) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_routes_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_routes_sample.py index c72c2cfacae1..1f599724cd18 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_routes_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_routes_sample.py @@ -24,7 +24,7 @@ name="First rule", description="Handle numbers starting with '+123'", number_pattern="\+123[0-9]+", trunks=[] ) ] -connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_string = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] client = SipRoutingClient.from_connection_string(connection_string) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_routes_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_routes_sample_async.py index 1f6938aec437..f9f317aa4326 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_routes_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_routes_sample_async.py @@ -26,7 +26,7 @@ name="First rule", description="Handle numbers starting with '+123'", number_pattern="\+123[0-9]+", trunks=[] ) ] -connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_string = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] client = SipRoutingClient.from_connection_string(connection_string) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_trunk_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_trunk_sample.py index cd6fe6f837ac..c52419a3a01d 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_trunk_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_trunk_sample.py @@ -21,9 +21,9 @@ import os from azure.communication.phonenumbers.siprouting import SipRoutingClient, SipTrunk -connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") -fqdn = os.getenv("COMMUNICATION_SAMPLES_TRUNK_FQDN") -signaling_port = os.getenv("COMMUNICATION_SAMPLES_SIGNALING_PORT") +connection_string = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] +fqdn = os.environ["COMMUNICATION_SAMPLES_TRUNK_FQDN"] +signaling_port = os.environ["COMMUNICATION_SAMPLES_SIGNALING_PORT"] client = SipRoutingClient.from_connection_string(connection_string) new_trunk = SipTrunk(fqdn=fqdn, sip_signaling_port=signaling_port) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_trunk_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_trunk_sample_async.py index 3b9f28ad62a1..867810f77f24 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_trunk_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_trunk_sample_async.py @@ -23,9 +23,9 @@ from azure.communication.phonenumbers.siprouting.aio import SipRoutingClient from azure.communication.phonenumbers.siprouting import SipTrunk -connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") -fqdn = os.getenv("COMMUNICATION_SAMPLES_TRUNK_FQDN") -signaling_port = os.getenv("COMMUNICATION_SAMPLES_SIGNALING_PORT") +connection_string = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] +fqdn = os.environ["COMMUNICATION_SAMPLES_TRUNK_FQDN"] +signaling_port = os.environ["COMMUNICATION_SAMPLES_SIGNALING_PORT"] client = SipRoutingClient.from_connection_string(connection_string) new_trunk = SipTrunk(fqdn=fqdn, sip_signaling_port=signaling_port) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_trunks_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_trunks_sample.py index 6d1beae587dc..254ef2aab9e3 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_trunks_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_trunks_sample.py @@ -21,10 +21,10 @@ import os from azure.communication.phonenumbers.siprouting import SipRoutingClient, SipTrunk -connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_string = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] client = SipRoutingClient.from_connection_string(connection_string) -fqdn = os.getenv("COMMUNICATION_SAMPLES_TRUNK_FQDN") -signaling_port = os.getenv("COMMUNICATION_SAMPLES_SIGNALING_PORT") +fqdn = os.environ["COMMUNICATION_SAMPLES_TRUNK_FQDN"] +signaling_port = os.environ["COMMUNICATION_SAMPLES_SIGNALING_PORT"] TRUNKS = [SipTrunk(fqdn=fqdn, sip_signaling_port=signaling_port)] diff --git a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_trunks_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_trunks_sample_async.py index 8d8714f0a28c..556d99d6ed3e 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_trunks_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/siprouting/set_sip_trunks_sample_async.py @@ -23,10 +23,10 @@ from azure.communication.phonenumbers.siprouting.aio import SipRoutingClient from azure.communication.phonenumbers.siprouting import SipTrunk -connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") +connection_string = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] client = SipRoutingClient.from_connection_string(connection_string) -fqdn = os.getenv("COMMUNICATION_SAMPLES_TRUNK_FQDN") -signaling_port = os.getenv("COMMUNICATION_SAMPLES_SIGNALING_PORT") +fqdn = os.environ["COMMUNICATION_SAMPLES_TRUNK_FQDN"] +signaling_port = os.environ["COMMUNICATION_SAMPLES_SIGNALING_PORT"] TRUNKS = [SipTrunk(fqdn=fqdn, sip_signaling_port=signaling_port)] diff --git a/sdk/communication/azure-communication-phonenumbers/samples/update_phone_number_capabilities_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/update_phone_number_capabilities_sample.py index e5bd584f3104..0747742b14c9 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/update_phone_number_capabilities_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/update_phone_number_capabilities_sample.py @@ -21,8 +21,8 @@ import os from azure.communication.phonenumbers import PhoneNumbersClient, PhoneNumberCapabilityType -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") -phone_number_to_update = os.getenv("AZURE_PHONE_NUMBER") # e.g. "+15551234567" +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] +phone_number_to_update = os.environ["AZURE_PHONE_NUMBER"] # e.g. "+15551234567" phone_numbers_client = PhoneNumbersClient.from_connection_string(connection_str) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/update_phone_number_capabilities_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/update_phone_number_capabilities_sample_async.py index ebfef32512c7..44fec057fe78 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/update_phone_number_capabilities_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/update_phone_number_capabilities_sample_async.py @@ -23,8 +23,8 @@ from azure.communication.phonenumbers.aio import PhoneNumbersClient from azure.communication.phonenumbers import PhoneNumberCapabilityType -connection_str = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING") -phone_number_to_update = os.getenv("AZURE_PHONE_NUMBER") # e.g. "+15551234567" +connection_str = os.environ["COMMUNICATION_SAMPLES_CONNECTION_STRING"] +phone_number_to_update = os.environ["AZURE_PHONE_NUMBER"] # e.g. "+15551234567" phone_numbers_client = PhoneNumbersClient.from_connection_string(connection_str) From 18c7e48c914e19ee75e204ff7bcccd942e429d4b Mon Sep 17 00:00:00 2001 From: Sofia Robles Sandoval Date: Thu, 24 Jul 2025 12:56:28 -0600 Subject: [PATCH 05/10] Fix pylint errors --- .../phonenumbers/_phone_numbers_client.py | 9 ++--- .../aio/_phone_numbers_client_async.py | 34 ++++++++++++------- .../siprouting/_sip_routing_client.py | 16 ++++++--- .../aio/_sip_routing_client_async.py | 16 ++++++--- 4 files changed, 51 insertions(+), 24 deletions(-) diff --git a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_phone_numbers_client.py b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_phone_numbers_client.py index 60eef35cb8dc..d39745c161ac 100644 --- a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_phone_numbers_client.py +++ b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_phone_numbers_client.py @@ -240,8 +240,8 @@ def begin_update_phone_number_capabilities( ) result_properties = poller.result().additional_properties - if (result_properties is not None and - "status" in result_properties and + if (result_properties is not None and + "status" in result_properties and result_properties["status"].lower() == "failed"): raise HttpResponseError( message=result_properties["error"]["message"]) @@ -273,7 +273,7 @@ def list_purchased_phone_numbers(self, **kwargs: Any) -> ItemPaged[PurchasedPhon :returns: An iterator of purchased phone numbers. :rtype: ~azure.core.paging.ItemPaged[~azure.communication.phonenumbers.PurchasedPhoneNumber] """ - return cast(ItemPaged[PurchasedPhoneNumber], + return cast(ItemPaged[PurchasedPhoneNumber], self._phone_number_client.phone_numbers.list_phone_numbers(**kwargs)) @distributed_trace @@ -499,7 +499,8 @@ def create_or_update_reservation( phone_numbers[number_id] = None # Cast to satisfy type checker - merge-patch operations allow None values - reservation = PhoneNumbersReservation(phone_numbers=cast(Optional[Dict[str, AvailablePhoneNumber]], phone_numbers)) + reservation = PhoneNumbersReservation( + phone_numbers=cast(Optional[Dict[str, AvailablePhoneNumber]], phone_numbers)) return self._phone_number_client.phone_numbers.create_or_update_reservation( reservation_id, reservation, **kwargs) diff --git a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/aio/_phone_numbers_client_async.py b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/aio/_phone_numbers_client_async.py index ff3b92076722..61c8aa3b31be 100644 --- a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/aio/_phone_numbers_client_async.py +++ b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/aio/_phone_numbers_client_async.py @@ -268,7 +268,10 @@ def list_purchased_phone_numbers(self, **kwargs: Any) -> AsyncItemPaged[Purchase ~azure.core.async_paging.AsyncItemPaged[~azure.communication.phonenumbers.PurchasedPhoneNumber] :raises ~azure.core.exceptions.HttpResponseError: """ - return cast(AsyncItemPaged[PurchasedPhoneNumber], self._phone_number_client.phone_numbers.list_phone_numbers(**kwargs)) + return cast( + AsyncItemPaged[PurchasedPhoneNumber], + self._phone_number_client.phone_numbers.list_phone_numbers(**kwargs) + ) @distributed_trace def list_available_countries(self, **kwargs: Any) -> AsyncItemPaged[PhoneNumberCountry]: @@ -284,9 +287,12 @@ def list_available_countries(self, **kwargs: Any) -> AsyncItemPaged[PhoneNumberC ~azure.core.async_paging.AsyncItemPaged[~azure.communication.phonenumbers.PhoneNumberCountry] :raises ~azure.core.exceptions.HttpResponseError: """ - return cast(AsyncItemPaged[PhoneNumberCountry], self._phone_number_client.phone_numbers.list_available_countries( - accept_language=self._accepted_language, **kwargs - )) + return cast( + AsyncItemPaged[PhoneNumberCountry], + self._phone_number_client.phone_numbers.list_available_countries( + accept_language=self._accepted_language, **kwargs + ) + ) @distributed_trace def list_available_localities(self, country_code: str, **kwargs: Any) -> AsyncItemPaged[PhoneNumberLocality]: @@ -307,13 +313,16 @@ def list_available_localities(self, country_code: str, **kwargs: Any) -> AsyncIt ~azure.core.async_paging.AsyncItemPaged[~azure.communication.phonenumbers.PhoneNumberLocality] :raises ~azure.core.exceptions.HttpResponseError: """ - return cast(AsyncItemPaged[PhoneNumberLocality], self._phone_number_client.phone_numbers.list_available_localities( - country_code, - administrative_division=kwargs.pop( - "administrative_division", None), - accept_language=self._accepted_language, - **kwargs - )) + return cast( + AsyncItemPaged[PhoneNumberLocality], + self._phone_number_client.phone_numbers.list_available_localities( + country_code, + administrative_division=kwargs.pop( + "administrative_division", None), + accept_language=self._accepted_language, + **kwargs + ) + ) @distributed_trace def list_available_offerings(self, country_code: str, **kwargs: Any) -> AsyncItemPaged[PhoneNumberOffering]: @@ -499,7 +508,8 @@ async def create_or_update_reservation( phone_numbers[number_id] = None # Cast to satisfy type checker - merge-patch operations allow None values - reservation = PhoneNumbersReservation(phone_numbers=cast(Optional[Dict[str, AvailablePhoneNumber]], phone_numbers)) + reservation = PhoneNumbersReservation( + phone_numbers=cast(Optional[Dict[str, AvailablePhoneNumber]], phone_numbers)) return await self._phone_number_client.phone_numbers.create_or_update_reservation( reservation_id, reservation, **kwargs diff --git a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_sip_routing_client.py b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_sip_routing_client.py index a2a775fadc7c..27e96f2d8c25 100644 --- a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_sip_routing_client.py +++ b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_sip_routing_client.py @@ -96,10 +96,10 @@ def get_trunk( if config.trunks is None: raise KeyError(f"Trunk with FQDN '{trunk_fqdn}' not found.") - + if trunk_fqdn not in config.trunks: raise KeyError(f"Trunk with FQDN '{trunk_fqdn}' not found.") - + trunk = config.trunks[trunk_fqdn] return SipTrunk(fqdn=trunk_fqdn, sip_signaling_port=trunk.sip_signaling_port) @@ -160,7 +160,10 @@ def extract_data(config): if config.trunks is None: list_of_elem = [] else: - list_of_elem = [SipTrunk(fqdn=k, sip_signaling_port=v.sip_signaling_port) for k, v in config.trunks.items()] + list_of_elem = [ + SipTrunk(fqdn=k, sip_signaling_port=v.sip_signaling_port) + for k, v in config.trunks.items() + ] return None, list_of_elem # pylint: disable=unused-argument @@ -186,7 +189,12 @@ def extract_data(config): list_of_elem = [] else: list_of_elem = [ - SipTrunkRoute(description=x.description, name=x.name, number_pattern=x.number_pattern, trunks=x.trunks) + SipTrunkRoute( + description=x.description, + name=x.name, + number_pattern=x.number_pattern, + trunks=x.trunks + ) for x in config.routes ] return None, list_of_elem diff --git a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/aio/_sip_routing_client_async.py b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/aio/_sip_routing_client_async.py index 7732ad3b2e84..16e693aca88c 100644 --- a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/aio/_sip_routing_client_async.py +++ b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/aio/_sip_routing_client_async.py @@ -101,10 +101,10 @@ async def get_trunk( if config.trunks is None: raise KeyError(f"Trunk with FQDN '{trunk_fqdn}' not found.") - + if trunk_fqdn not in config.trunks: raise KeyError(f"Trunk with FQDN '{trunk_fqdn}' not found.") - + trunk = config.trunks[trunk_fqdn] return SipTrunk(fqdn=trunk_fqdn, sip_signaling_port=trunk.sip_signaling_port) @@ -165,7 +165,10 @@ async def extract_data(config): if config.trunks is None: list_of_elem = [] else: - list_of_elem = [SipTrunk(fqdn=k, sip_signaling_port=v.sip_signaling_port) for k, v in config.trunks.items()] + list_of_elem = [ + SipTrunk(fqdn=k, sip_signaling_port=v.sip_signaling_port) + for k, v in config.trunks.items() + ] return None, AsyncList(list_of_elem) # pylint: disable=unused-argument @@ -191,7 +194,12 @@ async def extract_data(config): list_of_elem = [] else: list_of_elem = [ - SipTrunkRoute(description=x.description, name=x.name, number_pattern=x.number_pattern, trunks=x.trunks) + SipTrunkRoute( + description=x.description, + name=x.name, + number_pattern=x.number_pattern, + trunks=x.trunks + ) for x in config.routes ] return None, AsyncList(list_of_elem) From 80ad271be7bf974c40fb9743c57ebd2e6c1927a6 Mon Sep 17 00:00:00 2001 From: sofiar-msft Date: Wed, 30 Jul 2025 11:04:32 -0600 Subject: [PATCH 06/10] Update sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample_async.py Remove redundant initialization Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../samples/browse_and_reserve_phone_numbers_sample_async.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample_async.py index 3e46f3aa4bf7..ad5aef41ad96 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample_async.py @@ -46,11 +46,10 @@ async def browse_and_reserve_phone_numbers(): ) # Check if any errors occurred during reservation - numbers_with_error = [] if reservation.phone_numbers: numbers_with_error = [ n for n in reservation.phone_numbers.values() if n.status == "error"] - if any(numbers_with_error): + if reservation.phone_numbers and any(numbers_with_error): print("Errors occurred during reservation:") for number in numbers_with_error: error_code = number.error.code if number.error and number.error.code else "Unknown" From b4471b992abb2b16c99ffc40c45cae33bc65224e Mon Sep 17 00:00:00 2001 From: sofiar-msft Date: Wed, 30 Jul 2025 11:07:39 -0600 Subject: [PATCH 07/10] Update sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../samples/browse_and_reserve_phone_numbers_sample.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample.py index 560e1569bc9e..adc34dba960a 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_phone_numbers_sample.py @@ -45,7 +45,6 @@ def browse_and_reserve_phone_numbers(): ) # Check if any errors occurred during reservation - numbers_with_error = [] if reservation.phone_numbers: numbers_with_error = [ n for n in reservation.phone_numbers.values() if n.status == "error"] From fe64d47d597e11b2f6dc7c76ac9ea483b67c46be Mon Sep 17 00:00:00 2001 From: sofiar-msft Date: Wed, 30 Jul 2025 11:07:56 -0600 Subject: [PATCH 08/10] Update sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample_async.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../samples/browse_and_reserve_numbers_bulk_sample_async.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample_async.py b/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample_async.py index f6a37770e547..163a3260efe0 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample_async.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample_async.py @@ -50,7 +50,6 @@ async def browse_and_reserve_numbers_bulk(): ) # Check if any errors occurred during reservation - numbers_with_error = [] if reservation.phone_numbers: numbers_with_error = [ n for n in reservation.phone_numbers.values() if n.status == "error"] From 748610ea066bd1531dcb26f7ee74a17f25218f0e Mon Sep 17 00:00:00 2001 From: sofiar-msft Date: Wed, 30 Jul 2025 11:08:04 -0600 Subject: [PATCH 09/10] Update sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../samples/browse_and_reserve_numbers_bulk_sample.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample.py b/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample.py index a29fb7a9b5da..68b836e160d9 100644 --- a/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample.py +++ b/sdk/communication/azure-communication-phonenumbers/samples/browse_and_reserve_numbers_bulk_sample.py @@ -49,7 +49,6 @@ def browse_and_reserve_numbers_bulk(): ) # Check if any errors occurred during reservation - numbers_with_error = [] if reservation.phone_numbers: numbers_with_error = [ n for n in reservation.phone_numbers.values() if n.status == "error"] From 269f1b33605ab202d75fe4502e50923183e08316 Mon Sep 17 00:00:00 2001 From: Sofia Robles Sandoval Date: Wed, 30 Jul 2025 12:55:50 -0600 Subject: [PATCH 10/10] Update config trunks error message --- .../phonenumbers/siprouting/_sip_routing_client.py | 2 +- .../phonenumbers/siprouting/aio/_sip_routing_client_async.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_sip_routing_client.py b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_sip_routing_client.py index 27e96f2d8c25..d233bec4dc86 100644 --- a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_sip_routing_client.py +++ b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_sip_routing_client.py @@ -95,7 +95,7 @@ def get_trunk( config = self._rest_service.sip_routing.get(**kwargs) if config.trunks is None: - raise KeyError(f"Trunk with FQDN '{trunk_fqdn}' not found.") + raise KeyError("No SIP trunks are configured.") if trunk_fqdn not in config.trunks: raise KeyError(f"Trunk with FQDN '{trunk_fqdn}' not found.") diff --git a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/aio/_sip_routing_client_async.py b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/aio/_sip_routing_client_async.py index 16e693aca88c..f40a4c5d299a 100644 --- a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/aio/_sip_routing_client_async.py +++ b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/aio/_sip_routing_client_async.py @@ -100,7 +100,7 @@ async def get_trunk( config = await self._rest_service.sip_routing.get(**kwargs) if config.trunks is None: - raise KeyError(f"Trunk with FQDN '{trunk_fqdn}' not found.") + raise KeyError("No SIP trunks are configured.") if trunk_fqdn not in config.trunks: raise KeyError(f"Trunk with FQDN '{trunk_fqdn}' not found.")