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 package's pyproject.toml configuration and fixes all 28 type errors that were detected across 7 files.

Changes Made

Configuration

  • pyproject.toml: Enabled mypy by setting [tool.azure-sdk-build].mypy = true

Type Error Fixes

Core Utilities (_utils.py)

  • Added proper imports for List, Tuple, Optional, ChatParticipant, and ChatError
  • Fixed type annotations from invalid list[(ChatThreadParticipant, ChatError)] to correct List[Tuple[Optional[ChatParticipant], ChatError]]
  • Corrected Dict(str, ChatThreadParticipant) to Dict[str, ChatParticipant]

Shared Policy (_shared/policy.py)

  • Added # type: ignore[import-not-found] for optional yarl dependency import

Identifier Serialization (_communication_identifier_serializer.py)

  • Fixed handling of None values for raw_id in CommunicationUserIdentifier and UnknownIdentifier constructors
  • Added explicit string casting for enum keys in dictionary assignment
  • Added type ignore for legitimate assignment type mismatch

Chat Thread Client (_chat_thread_client.py)

  • Added missing imports for ChatError and CommunicationIdentifierModel
  • Fixed return type mismatches between ItemPaged and Iterable with appropriate type ignores
  • Corrected method parameter types for remove_chat_participant by properly constructing CommunicationIdentifierModel
  • Updated return type annotations to match actual implementation (Optional[ChatParticipant] in tuples)

Chat Client (_chat_client.py)

  • Fixed variable shadowing issue in create_chat_thread method
  • Added missing import for ChatThreadItem
  • Fixed return type mismatch with type ignore for generated client compatibility

Async Implementations

  • aio/_chat_thread_client_async.py: Fixed Optional parameter types for methods with None defaults, return type mismatches, and method parameter types
  • aio/_chat_client_async.py: Fixed variable shadowing and return type compatibility issues

Testing

  • ✅ mypy now reports "Success: no issues found in 43 source files"
  • ✅ All type errors resolved without breaking existing functionality
  • ✅ Changes are minimal and surgical, preserving original behavior

Impact

This change improves code quality and developer experience by:

  • Enabling static type checking during CI/CD
  • Catching potential type-related bugs early
  • Improving IDE support with better type hints
  • Ensuring consistency with Azure SDK typing standards

The fixes are backward compatible and do not change any public APIs or runtime behavior.


💡 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 6, 2025
Copilot AI requested a review from kristapratico June 6, 2025 23:08
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