Skip to content

Enable mypy static type checking for azure-communication-phonenumbers package#34

Closed
Copilot wants to merge 17 commits intomainfrom
copilot/fix-ac4f4309-9581-4dca-9bf9-cb8657d29c5a
Closed

Enable mypy static type checking for azure-communication-phonenumbers package#34
Copilot wants to merge 17 commits intomainfrom
copilot/fix-ac4f4309-9581-4dca-9bf9-cb8657d29c5a

Conversation

Copy link

Copilot AI commented Jun 9, 2025

Overview

This PR enables mypy static type checking for the azure-communication-phonenumbers package by setting [tool.azure-sdk-build].mypy = true in the configuration and fixing all resulting type errors.

Changes Made

Configuration

  • ✅ Enabled mypy in pyproject.toml by setting mypy = true

Core PhoneNumbersClient Fixes

  • Constructor type safety: Fixed from_connection_string method to properly wrap access key in AzureKeyCredential
  • Optional type handling: Enhanced create_or_update_reservation method to handle Optional[AvailablePhoneNumber] types correctly with proper null checks
  • Return type casting: Added proper type casting for all pagination methods returning ItemPaged/AsyncItemPaged to resolve generated code type mismatches
  • Null safety: Added proper null checks for optional properties in error handling

SIP Routing Client Fixes

  • Constructor signatures: Updated type annotations to accept Union[TokenCredential, AzureKeyCredential] in both sync and async versions
  • Optional dict handling: Added comprehensive null checks before indexing and iterating over optional dictionaries
  • API compatibility: Added type: ignore comments for cases where the API accepts None values but type definitions don't reflect this
  • Return type corrections: Fixed incorrect return type annotation in async _update_trunks_ method

Generated Code Fixes

  • Missing attributes: Added __all__: list[str] = [] to _patch.py files to resolve missing attribute errors
  • Import safety: Made yarl import conditionally available for type checking to handle optional dependencies

Files Modified

azure/communication/phonenumbers/_phone_numbers_client.py          (+46/-37)
azure/communication/phonenumbers/aio/_phone_numbers_client_async.py (+43/-36)
azure/communication/phonenumbers/siprouting/_sip_routing_client.py  (+16/-6)
azure/communication/phonenumbers/siprouting/aio/_sip_routing_client_async.py (+17/-7)
azure/communication/phonenumbers/_shared/policy.py                 (+7/-1)
azure/communication/phonenumbers/siprouting/_generated/_patch.py   (+3/-0)
azure/communication/phonenumbers/siprouting/_generated/aio/_patch.py (+3/-0)
pyproject.toml                                                     (+1/-1)

Validation

  • ✅ All 59 source files now pass mypy type checking without errors
  • ✅ Existing functionality preserved with minimal, surgical changes
  • ✅ Type safety improved across the entire package

Result

The azure-communication-phonenumbers package is now fully compliant with mypy static type checking, improving code reliability and developer experience while maintaining backward compatibility.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits June 9, 2025 16:36
Co-authored-by: kristapratico <31998003+kristapratico@users.noreply.github.com>
…s package

Co-authored-by: kristapratico <31998003+kristapratico@users.noreply.github.com>
Copilot AI changed the title [WIP] Enable mypy checks and fix errors in azure-communication-phonenumbers Enable mypy static type checking for azure-communication-phonenumbers package Jun 9, 2025
Copilot AI requested a review from kristapratico June 9, 2025 16:49
@github-actions
Copy link

Hi @Copilot. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants