Skip to content

AnnotationSpecsAccessorに定型指摘に関するメソッドを追加しました - #761

Merged
yuji38kwmt merged 1 commit into
mainfrom
add-inspection-phrase-accessor
Jul 26, 2026
Merged

AnnotationSpecsAccessorに定型指摘に関するメソッドを追加しました#761
yuji38kwmt merged 1 commit into
mainfrom
add-inspection-phrase-accessor

Conversation

@yuji38kwmt

Copy link
Copy Markdown
Collaborator

Summary

  • Add InspectionPhrase TypedDict and keep inspection_phrases on AnnotationSpecsAccessor
  • Add ID-based get_inspection_phrase helpers
  • Add tests for ID lookup and not-found behavior

Tests

  • make format
  • make lint
  • uv run pytest tests/util/test_annotation_specs.py

@kci-pr-agent

kci-pr-agent Bot commented Jul 26, 2026

Copy link
Copy Markdown

Title

Add inspection phrase accessor


Description

  • InspectionPhrase TypedDict を追加

  • get_inspection_phrase 関数を実装

  • AnnotationSpecsAccessor に定型指摘取得メソッド追加

  • テストで取得とエラーケースを検証


Changes walkthrough 📝

Relevant files
Enhancement
annotation_specs.py
定型指摘アクセサ機能の追加                                                                                       

annofabapi/util/annotation_specs.py

  • InspectionPhrase TypedDict 定義追加
  • get_inspection_phrase 関数実装
  • AnnotationSpecsAccessorinspection_phrases プロパティとメソッド追加
  • +51/-0   
    Tests
    test_annotation_specs.py
    定型指摘テストの追加                                                                                             

    tests/util/test_annotation_specs.py

  • テストセットアップに inspection_phrases データ追加
  • get_inspection_phrase の正常系・異常系テスト追加
  • +47/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @kci-pr-agent

    kci-pr-agent Bot commented Jul 26, 2026

    Copy link
    Copy Markdown

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Missing Key Validation

    annotation_specsにinspection_phrasesキーが存在しない場合、__init__内でKeyErrorが発生します。デフォルト値の設定や存在チェックの追加を検討してください。

    def __init__(self, annotation_specs: dict[str, Any]) -> None:
        self.annotation_specs = annotation_specs
        self.labels: list[LabelDefinition] = annotation_specs["labels"]
        self.additionals: list[AttributeDefinition] = annotation_specs["additionals"]
        self.inspection_phrases: list[InspectionPhrase] = annotation_specs["inspection_phrases"]
    テスト不足

    同一のinspection_phrase_idを持つ要素が複数ある場合の例外処理がテストされていません。重複ID時のエラーケースを追加で検証すると良いでしょう。

        inspection_phrase = get_inspection_phrase(self.inspection_phrases, inspection_phrase_id="1")
        assert inspection_phrase["id"] == "1"
    
    def test_get_inspection_phrase_not_found(self):
        with pytest.raises(ValueError):
            get_inspection_phrase(self.inspection_phrases, inspection_phrase_id="3")

    @kci-pr-agent

    kci-pr-agent Bot commented Jul 26, 2026

    Copy link
    Copy Markdown

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    @yuji38kwmt yuji38kwmt changed the title Add inspection phrase accessor AnnotationSpecsAccessorに定型指摘に関するメソッドを追加しました Jul 26, 2026
    @yuji38kwmt
    yuji38kwmt requested a review from Copilot July 26, 2026 16:16
    @yuji38kwmt
    yuji38kwmt merged commit b3729a1 into main Jul 26, 2026
    10 checks passed
    @yuji38kwmt
    yuji38kwmt deleted the add-inspection-phrase-accessor branch July 26, 2026 16:17

    Copilot AI left a comment

    Copy link
    Copy Markdown

    Choose a reason for hiding this comment

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

    Pull request overview

    AnnotationSpecsAccessor に「定型指摘(inspection_phrases)」を扱う型・取得ユーティリティを追加し、IDベースで定型指摘を取り出せるようにする変更です。アノテーション仕様(annotation specs)周りの参照APIを拡張し、呼び出し側の実装を簡潔にする目的に沿っています。

    Changes:

    • InspectionPhrase(TypedDict)を追加し、annotation specs 内の inspection_phrases を型付け
    • get_inspection_phrase()AnnotationSpecsAccessor.get_inspection_phrase() により、IDで定型指摘を取得可能に
    • ID取得と not-found のテストを追加

    Reviewed changes

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

    File Description
    annofabapi/util/annotation_specs.py 定型指摘のTypedDictとID取得ヘルパー、Accessorメソッドを追加
    tests/util/test_annotation_specs.py 定型指摘のID取得・not-found 挙動のテストを追加

    Comment on lines 303 to +307
    def __init__(self, annotation_specs: dict[str, Any]) -> None:
    self.annotation_specs = annotation_specs
    self.labels: list[LabelDefinition] = annotation_specs["labels"]
    self.additionals: list[AttributeDefinition] = annotation_specs["additionals"]
    self.inspection_phrases: list[InspectionPhrase] = annotation_specs["inspection_phrases"]
    Comment on lines +193 to +195
    def test_get_inspection_phrase_not_found(self):
    with pytest.raises(ValueError):
    get_inspection_phrase(self.inspection_phrases, inspection_phrase_id="3")
    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