Enable mypy static type checking for azure-communication-chat package #25
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 settingmypy = truein the pyproject.toml configuration and fixing all resulting type errors.Changes Made
Configuration
mypy = falsetomypy = trueType Fixes
Fixed 28 mypy errors across 6 files:
Core Library Files
_utils.py:
List,Tuple,Dict,TYPE_CHECKING)list[(A, B)]→List[Tuple[A, B]])ChatThreadParticipant→ChatParticipant)_communication_identifier_serializer.py:
cast()CommunicationUserIdentifierandUnknownIdentifieryarldependency_chat_thread_client.py:
ItemPaged,ChatError,CommunicationIdentifierModel)cast()forItemPagedvsIterabletypesremove_chat_participantcall to use proper model construction_chat_client.py:
ItemPaged,ChatThreadItem,cast)create_chat_threadmethodcast()for return type compatibilityAsync Library Files
aio/_chat_thread_client_async.py:
str = None→Optional[str] = None)cast()for async return typesremove_chat_participantasync callaio/_chat_client_async.py:
create_chat_threadmethodcast()forAsyncItemPagedreturn type compatibilityTechnical Details
Type Casting Strategy
Used
cast()to resolve type mismatches between generated client code (returnsIterable/AsyncIterable) and public API expectations (ItemPaged/AsyncItemPaged). This is safe because the runtime objects are actually the expected paged types.Import Organization
TYPE_CHECKINGimports to avoid circular dependenciesValidation
✅ mypy check passes:
Success: no issues found in 43 source filesThe package now fully complies with mypy static type checking standards, improving type safety and developer experience for users of the azure-communication-chat SDK.
💡 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.