20260804 1 - #1716
Conversation
- 新しいサブコマンド `list_all_with_replies` を実装 - コメント一覧に返信コメントを含める処理を追加 - ドキュメントを更新し、コマンドの使用例を追加 - テストケースを追加し、機能の動作を確認
Title20260804 1 Description
Changes walkthrough 📝
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
| import logging | ||
| from collections import defaultdict | ||
| from collections.abc import Collection | ||
| from typing import Any | ||
|
|
||
| import logging | ||
| from collections import defaultdict | ||
| from collections.abc import Collection | ||
| from typing import Any |
There was a problem hiding this comment.
Suggestion: インポート文が重複して宣言されているため、1回にまとめて可読性と保守性を向上させましょう。 [general, importance: 5]
| import logging | |
| from collections import defaultdict | |
| from collections.abc import Collection | |
| from typing import Any | |
| import logging | |
| from collections import defaultdict | |
| from collections.abc import Collection | |
| from typing import Any | |
| import logging | |
| from collections import defaultdict | |
| from collections.abc import Collection | |
| from typing import Any |
| def _copy_reply_comment(comment: dict[str, Any]) -> dict[str, Any]: | ||
| reply_comment = dict(comment) | ||
| reply_comment.pop("reply_count", None) |
There was a problem hiding this comment.
Suggestion: _copy_reply_comment は機能が _create_reply_comment_for_output と重複しているため、どちらかに統一して冗長な定義を削除しましょう。 [general, importance: 5]
| def _copy_reply_comment(comment: dict[str, Any]) -> dict[str, Any]: | |
| reply_comment = dict(comment) | |
| reply_comment.pop("reply_count", None) | |
| # 不要な `_copy_reply_comment` 関数を削除し、`_create_reply_comment_for_output` を使用します。 |
| return output_reply_comment | ||
|
|
||
|
|
||
| def create_comment_list_with_replies(comment_list: Collection[dict[str, Any]]) -> list[dict[str, Any]]: |
There was a problem hiding this comment.
Suggestion: 同じ名前の関数定義が3回繰り返されており、後勝ちでしか使われないので1つに統合し、不要な重複を排除しましょう。 [possible issue, importance: 8]
There was a problem hiding this comment.
Pull request overview
コメント一覧出力に「ルートコメントへ返信コメント一覧(reply_comments)を付与する」機能を追加し、タスク単位・プロジェクト全体単位で取得できる新サブコマンドと、その利用方法ドキュメント/テストを追加するPRです。
Changes:
comment list_with_replies/comment list_all_with_repliesサブコマンドを追加- 返信コメントをルートコメントへぶら下げるためのユーティリティ
create_comment_list_with_repliesを追加 - 新サブコマンドのドキュメントとユーティリティのテストを追加
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/comment/test_list_all_comment_with_replies.py | create_comment_list_with_replies の並び替え・返信付与・孤児返信スキップのテストを追加 |
| docs/command_reference/comment/list_with_replies.rst | comment list_with_replies の使い方と出力例を追加 |
| docs/command_reference/comment/list_all_with_replies.rst | comment list_all_with_replies の使い方と出力例を追加 |
| docs/command_reference/comment/index.rst | comment配下のコマンド一覧に2コマンドを追加 |
| annofabcli/comment/utils.py | 返信コメントをルートコメントへ集約する処理を追加(ただし現状は重複定義が混入) |
| annofabcli/comment/subcommand_comment.py | commentサブコマンドへ2コマンドを登録 |
| annofabcli/comment/list_comment_with_replies.py | タスク指定で返信付きコメント一覧を出力する新コマンドを追加 |
| annofabcli/comment/list_all_comment_with_replies.py | 全件(/条件指定)で返信付きコメント一覧を出力する新コマンドを追加 |
Suppressed comments (1)
annofabcli/comment/utils.py:99
_get_comment_datetime_for_sorting/create_comment_list_with_replies/_create_reply_comment_for_outputなどがファイル内で複数回定義されています(再定義)。Pythonでは後勝ちで上書きされるため、前半の実装が実質的に死んだコードになり、意図しない挙動・保守性低下・lintエラー(F811)につながります。実装は1箇所に集約し、重複定義を削除してください。
def _get_comment_datetime_for_sorting(comment: dict[str, Any]) -> str:
return comment["datetime_for_sorting"]
def create_comment_list_with_replies(comment_list: Collection[dict[str, Any]]) -> list[dict[str, Any]]:
"""ルートコメントに返信コメント一覧を付与したコメント一覧を生成します。
| import logging | ||
| from collections import defaultdict | ||
| from collections.abc import Collection | ||
| from typing import Any | ||
|
|
||
| import logging | ||
| from collections import defaultdict | ||
| from collections.abc import Collection | ||
| from typing import Any | ||
|
|
||
| import logging | ||
| from collections import defaultdict | ||
| from collections.abc import Collection | ||
| from typing import Any | ||
|
|
||
| from annofabapi.models import CommentType | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
| description = ( | ||
| "すべてのルートコメントに返信コメント一覧を付与して出力します。\n" | ||
| "コメント一覧は、コマンドを実行した日の02:00(JST)頃の状態です。最新のコメント情報を取得したい場合は、 ``annofabcli comment list`` コマンドを実行してください。" | ||
| ) |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
Suppressed comments (2)
annofabcli/comment/list_all_comment_with_replies.py:101
- ヘルプ文の注記が「最新のコメント情報を取得したい場合は
annofabcli comment list」となっていますが、このコマンドは返信付きの出力なので、最新情報を取得するコマンドはlist_with_repliesの方が適切です。ドキュメント(list_all_with_replies.rst)とも不整合になります。
description = (
"すべてのルートコメントに返信コメント一覧を付与して出力します。\n"
"コメント一覧は、コマンドを実行した日の02:00(JST)頃の状態です。最新のコメント情報を取得したい場合は、 ``annofabcli comment list`` コマンドを実行してください。"
)
tests/comment/test_list_all_comment_with_replies.py:73
- このテストはWARNINGログの捕捉をpytestのデフォルト設定に依存しています。テストスイート側でログレベル設定が変わると意図した警告がcaplogに入らず、テストが不安定になる可能性があるので、対象ロガー・レベルを明示した方が安全です。
actual = create_comment_list_with_replies([reply_comment, root_comment])
No description provided.