Skip to content

Fix mypy and pylint errors for communications chat and rooms#43283

Closed
natekimball-msft wants to merge 1 commit intomainfrom
natekimball/communication-chat-rooms-pylint-mypy-fixes
Closed

Fix mypy and pylint errors for communications chat and rooms#43283
natekimball-msft wants to merge 1 commit intomainfrom
natekimball/communication-chat-rooms-pylint-mypy-fixes

Conversation

@natekimball-msft
Copy link
Member

Description

This PR is a follow up to the conversation in this PR: #43090 (comment)

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses mypy and pylint errors in the Azure Communication Chat and Rooms SDKs by replacing legacy type hints with modern type annotations and adding proper type ignores for known type system limitations.

Key Changes

  • Converted legacy comment-style type hints (# type:) to modern Python type annotations
  • Added type: ignore comments for mypy compatibility issues where types don't align perfectly
  • Updated function signatures to use keyword-only parameters where appropriate
  • Fixed version extraction logic in setup.py files to handle potential None values

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
setup.py files Fixed version extraction to handle None regex matches properly
_shared/utils.py files Updated type hints for token credential functions
Client files Modernized type annotations and added mypy ignore comments
_utils.py Updated type annotations for error response converter
_communication_identifier_serializer.py Added type annotations and ignore comments
_shared/token_utils.py Added ignore for untyped import
Comments suppressed due to low confidence (1)

from datetime import datetime, timezone
from typing import Tuple, Any, List, Optional
import isodate
import isodate # type: ignore[import-untyped]
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding a py.typed file to the isodate package or use a typed alternative if available, rather than ignoring the untyped import.

Copilot uses AI. Check for mistakes.
Comment on lines +113 to 115
create_room_request["participants"] = { # type: ignore[assignment]
p.communication_identifier.raw_id: {"role": p.role} for p in participants
}
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The type ignore comment suggests a type system issue. Consider defining a proper TypedDict for the participants structure to improve type safety.

Copilot uses AI. Check for mistakes.
Comment on lines +112 to 114
create_room_request["participants"] = { # type: ignore[assignment]
p.communication_identifier.raw_id: {"role": p.role} for p in participants
}
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The type ignore comment suggests a type system issue. Consider defining a proper TypedDict for the participants structure to improve type safety.

Copilot uses AI. Check for mistakes.
Copy link
Member

@annatisch annatisch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these updates!
There are a few typing errors here that surprise me, and I would like to dig into it a little more to find out why mypy was complaining.

# pylint: disable=unused-import,ungrouped-imports
from datetime import datetime
from azure.core.paging import ItemPaged
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than pass here, we can just remove the whole TYPE_CHECKING block (and remove the TYPE_CHECKING import on line 7).

# type: (...) -> ChatThreadClient
thread_id: str,
**kwargs: Any
) -> "ChatThreadClient":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
) -> "ChatThreadClient":
) -> ChatThreadClient:

Shouldn't need quotes here.

):
# type: (...) -> None
endpoint: str,
credential: "CommunicationTokenCredential",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
credential: "CommunicationTokenCredential",
credential: CommunicationTokenCredential,

Shouldn't need quotes here.

)

return create_chat_thread_result
return create_chat_thread_result # type: ignore[return-value]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be a typing error - I think if you rename the variable on line 172 this (and the typing error on 172) should go away.

start_time = kwargs.pop("start_time", None)

return self._client.chat.list_chat_threads(max_page_size=results_per_page, start_time=start_time, **kwargs)
return self._client.chat.list_chat_threads( # type: ignore[return-value]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm this shouldn't be a typing error?


def create_token_credential():
# type: () -> FakeTokenCredential or get_credential
# type: () -> Any
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just remove the old-style type hints completely from this file - there's not really much benefit to having the typing in test utils anyway.

@github-actions
Copy link

Hi @natekimball-msft. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days.

@github-actions github-actions bot added the no-recent-activity There has been no recent activity on this issue. label Dec 12, 2025
@github-actions
Copy link

Hi @natekimball-msft. Thank you for your contribution. Since there hasn't been recent engagement, we're going to close this out. Feel free to respond with a comment containing /reopen if you'd like to continue working on these changes. Please be sure to use the command to reopen or remove the no-recent-activity label; otherwise, this is likely to be closed again with the next cleanup pass.

@github-actions github-actions bot closed this Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants