Enable mypy static type checking for azure-communication-chat package #32
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR enables mypy static type checking for the
azure-communication-chatpackage by setting[tool.azure-sdk-build].mypy = truein the pyproject.toml configuration and fixing all identified type errors.Changes Made
Configuration
mypy = trueType Error Fixes
Core Type Issues
CommunicationErrorResponseConverter.convert()methodidentifier_to_generated_model()for proper model conversionReturn Type Mismatches
The generated operations return
Iterablebut the public APIs declareItemPagedreturn types. Since the generated code actually returnsItemPagedobjects (despite incorrect type annotations), added# type: ignore[return-value]comments to:_chat_thread_client.py:list_read_receipts(),list_messages(),list_participants()_chat_client.py:list_chat_threads()aio/directoryParameter Type Issues
remove_chat_participant()method to use properCommunicationIdentifierModelinstead of serialized dict= NonetoOptional[Type] = Nonefor:update_topic(topic)send_message(metadata)update_message(content, metadata)Variable Reuse Issues
create_chat_thread()where the same variable was used for both generated and local model typesMissing Imports
ChatErrorandChatThreadItemwhere neededValidation
All mypy type errors have been resolved. Running
mypy azure/communication/chatnow passes cleanly with only informational notes about generated code (which is expected and normal).The changes are minimal and surgical - primarily adding type annotations, imports, and type ignore comments where the generated code has incorrect type signatures. No runtime behavior has been changed.
Files Changed
pyproject.toml- Enable mypy_chat_client.py- Fix variable reuse and return types_chat_thread_client.py- Fix parameter types and return types_communication_identifier_serializer.py- Fix type annotations and add helper function_utils.py- Add type imports and fix return typeaio/_chat_client_async.py- Fix async equivalentsaio/_chat_thread_client_async.py- Fix async equivalents💡 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.