Skip to content

Conversation

Copy link

Copilot AI commented Jun 6, 2025

Summary

This PR enables mypy static type checking for the azure-communication-chat package by setting mypy = true in the pyproject.toml configuration and fixing all resulting type errors.

Changes Made

Configuration

  • pyproject.toml: Enabled mypy static type checking by changing mypy = false to mypy = true

Type Fixes

Fixed 28 mypy errors across 6 files:

Core Library Files

  • _utils.py:

    • Added proper typing imports (List, Tuple, Dict, TYPE_CHECKING)
    • Fixed invalid type annotation syntax (list[(A, B)]List[Tuple[A, B]])
    • Corrected type references (ChatThreadParticipantChatParticipant)
    • Added null checks to prevent returning None values in tuples
  • _communication_identifier_serializer.py:

    • Fixed dictionary key assignment type issues using cast()
    • Corrected constructor calls for CommunicationUserIdentifier and UnknownIdentifier
    • Added missing import suppression for optional yarl dependency
  • _chat_thread_client.py:

    • Added missing imports (ItemPaged, ChatError, CommunicationIdentifierModel)
    • Fixed return type mismatches using cast() for ItemPaged vs Iterable types
    • Corrected remove_chat_participant call to use proper model construction
  • _chat_client.py:

    • Added missing imports (ItemPaged, ChatThreadItem, cast)
    • Fixed variable name collision in create_chat_thread method
    • Applied cast() for return type compatibility

Async Library Files

  • aio/_chat_thread_client_async.py:

    • Fixed Optional parameter type annotations (str = NoneOptional[str] = None)
    • Added missing imports and cast() for async return types
    • Fixed remove_chat_participant async call
  • aio/_chat_client_async.py:

    • Fixed variable name collision in async create_chat_thread method
    • Applied cast() for AsyncItemPaged return type compatibility

Technical Details

Type Casting Strategy

Used cast() to resolve type mismatches between generated client code (returns Iterable/AsyncIterable) and public API expectations (ItemPaged/AsyncItemPaged). This is safe because the runtime objects are actually the expected paged types.

Import Organization

  • Used TYPE_CHECKING imports to avoid circular dependencies
  • Added proper type annotations while maintaining runtime compatibility
  • Imported missing model types from generated code

Validation

mypy check passes: Success: no issues found in 43 source files

The 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.

Copilot AI and others added 2 commits June 6, 2025 22:22
Copilot AI changed the title [WIP] Enable mypy checks and fix azure-communication-chat errors Enable mypy static type checking for azure-communication-chat package Jun 6, 2025
Copilot AI requested a review from kristapratico June 6, 2025 22:31
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