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 [tool.azure-sdk-build].mypy = true in the pyproject.toml configuration and fixing all identified type errors.

Changes Made

Configuration

  • pyproject.toml: Enabled mypy type checking by setting mypy = true

Type Error Fixes

Core Type Issues

  • _utils.py: Added proper type imports and fixed type annotations for CommunicationErrorResponseConverter.convert() method
  • _communication_identifier_serializer.py:
    • Fixed dictionary assignment type compatibility issues
    • Added helper function identifier_to_generated_model() for proper model conversion
    • Fixed Optional parameter handling

Return Type Mismatches

The generated operations return Iterable but the public APIs declare ItemPaged return types. Since the generated code actually returns ItemPaged objects (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()
  • Async equivalents in aio/ directory

Parameter Type Issues

  • _chat_thread_client.py: Fixed remove_chat_participant() method to use proper CommunicationIdentifierModel instead of serialized dict
  • Async clients: Fixed default parameter types from = None to Optional[Type] = None for:
    • update_topic(topic)
    • send_message(metadata)
    • update_message(content, metadata)

Variable Reuse Issues

  • _chat_client.py and _chat_client_async.py: Fixed variable name conflicts in create_chat_thread() where the same variable was used for both generated and local model types

Missing Imports

  • Added missing imports for ChatError and ChatThreadItem where needed
  • Added proper TYPE_CHECKING imports to avoid circular dependencies

Validation

All mypy type errors have been resolved. Running mypy azure/communication/chat now 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 type
  • aio/_chat_client_async.py - Fix async equivalents
  • aio/_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.

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