属性制約向けの意味ベースASTと可読表示を追加#752
Conversation
Title属性制約向けの意味ベースASTと可読表示を追加 Description
Changes walkthrough 📝
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
There was a problem hiding this comment.
Pull request overview
属性制約(annotation_specs の restrictions)を、従来の fluent API を維持しつつ、LLM/CLI 連携しやすい「名前ベースの意味AST」と「可読表示」に変換できる層を追加するPRです。
Changes:
Restrictionに dict/AST/Python式/可読表示への変換・復元APIを追加RestrictionAstと、属性型ごとの許可AST種別等を返す catalog 生成を追加- 追加機能の round-trip・不正ケース・可読表示・catalog のテストを追加
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 11 comments.
| File | Description |
|---|---|
| annofabapi/util/attribute_restrictions.py | Restriction/AST 相互変換・可読表示・catalog 出力などの中核実装を追加 |
| tests/util/test_attribute_restrictions.py | 新API(from/to dict, AST, human readable, catalog)のテストを追加 |
…テストコード、作業の進め方、レビューに関するセクションを削除
There was a problem hiding this comment.
Pull request overview
属性制約を「属性名ベース」で扱える意味ベースAST(RestrictionAst)層を追加し、既存の fluent API(Restriction)と相互変換・可読表示・LLM向けカタログ出力を可能にする変更です。Annofab API の restrictions JSON と、人間/LLM/CLI が扱いやすい表現の橋渡しを annofabapi.util に組み込みます。
Changes:
Restrictionに AST 変換(to_ast/from_ast)と可読表示(to_human_readable)、dict復元(from_dict)を追加RestrictionAst(dataclass)と、属性ごとの利用可能AST種別などを返すget_attribute_restriction_catalog()を追加- round-trip / 不正ケース / 可読表示 / catalog 出力のテストを追加
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
annofabapi/util/attribute_restrictions.py |
Restriction↔AST変換、可読表示、カタログ生成、dict復元などを追加 |
tests/util/test_attribute_restrictions.py |
AST round-trip・不正系・可読表示・カタログ出力のテストを追加 |
AGENTS.md |
エージェント向けの作業/レビュー方針を追加 |
.github/copilot-instructions.md |
参照先を AGENTS.md / .agents/skills/ に変更 |
.codex/config.toml |
Codex 実行用の設定を追加 |
.agents/skills/test-writing/SKILL.md |
テスト方針(pytest.raisesの扱い等)を追加 |
.agents/skills/python-coding-style/SKILL.md |
Python コーディングスタイルの方針を追加 |
| with pytest.raises(ValueError, match="属性'tracking'\\(type='tracking'\\)ではAST種別'matches_string'を利用できません。"): | ||
| ast.to_restriction(accessor.annotation_specs) |
Co-authored-by: Copilot <copilot@github.com>
AGENTS.mdにコード修正方針に関する説明を追加 Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
Pull request overview
属性制約(additional_data の restrictions)を、属性IDベースの既存 fluent API を維持したまま「属性名ベースで扱える意味ベースAST」に変換・復元できる層を追加し、CLI/LLM 連携や人間向け表示、カタログ出力を可能にするPRです。
Changes:
Restriction⇄RestrictionAstの相互変換(AST種別RestrictionAstType)と human-readable 表示を追加- 属性型ごとの許可AST種別や選択肢/ラベル名を返す
get_attribute_restriction_catalog()を追加 annotation_specsユーティリティに TypedDict を導入し、テストを拡充(round-trip / 不正ケース / 表示 / catalog)
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
annofabapi/util/attribute_restrictions.py |
RestrictionAst/変換/可読表示/カタログ出力の実装を追加 |
annofabapi/util/annotation_specs.py |
annotation_specs 周りを TypedDict で型付けし、choice/label/attribute取得関数を更新 |
tests/util/test_attribute_restrictions.py |
AST round-trip・不正ケース・可読表示・catalog のテストを追加 |
tests/util/test_annotation_specs.py |
choice の型注釈を追加し、TypedDict導入に追従 |
AGENTS.md |
エージェント運用・作業方針のドキュメントを追加 |
.github/copilot-instructions.md |
参照先を AGENTS.md / .agents/skills/ に整理 |
.codex/config.toml |
Codex 実行設定(sandbox/ネットワーク/承認ポリシー等)を追加 |
.agents/skills/test-writing/SKILL.md |
テスト方針(pytest.raises等)を明文化 |
.agents/skills/python-coding-style/SKILL.md |
Python コーディングスタイルを明文化 |
| for attribute in accessor.additionals: | ||
| attribute_type = attribute["type"] | ||
| choice_names = None | ||
| label_names = None | ||
| match attribute_type: | ||
| case "choice" | "select": | ||
| choice_names = [get_english_message(choice["name"]) for choice in _get_attribute_choices(attribute)] | ||
| case "link": | ||
| label_names = [get_english_message(label["label_name"]) for label in accessor.labels] | ||
| item = AttributeRestrictionCatalogItem( |
There was a problem hiding this comment.
Pull request overview
属性制約を「IDベースのRestriction(JSON)」だけでなく「属性名ベースの意味AST(RestrictionAst)」として扱える層を追加し、LLM/CLI連携や人間向け表示・属性カタログ出力を可能にするPRです。
Changes:
Restriction⇄RestrictionAstの相互変換と、human-readable 表示を追加- 属性型ごとの許可AST種別・選択肢/ラベル名を返すカタログAPIを追加
annotation_specs周りの型(TypedDict)強化と、上記機能のテスト追加
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
annofabapi/util/attribute_restrictions.py |
意味ベースAST・相互変換・human-readable・属性カタログ生成を追加 |
annofabapi/util/annotation_specs.py |
AttributeDefinition等のTypedDict導入、関連関数/Accessorの型を具体化 |
tests/util/test_attribute_restrictions.py |
AST round-trip、妥当性違反、可読表示、catalog出力のテストを追加 |
tests/util/test_annotation_specs.py |
AttributeChoice 型注釈の追加 |
AGENTS.md |
エージェント作業/方針ドキュメントを追加 |
.github/copilot-instructions.md |
参照先を AGENTS.md 等に集約 |
.codex/config.toml |
Codex実行設定を追加 |
.agents/skills/test-writing/SKILL.md |
テスト作法のスキル定義を追加 |
.agents/skills/python-coding-style/SKILL.md |
Pythonコーディング作法のスキル定義を追加 |
There was a problem hiding this comment.
Pull request overview
属性制約を「属性ID中心のAPI JSON」だけでなく「属性名中心の意味ベースAST」として扱えるようにし、LLM/CLI連携しやすい変換・可読表示・カタログ出力までを annofabapi.util 層に追加するPRです。
Changes:
- 属性制約の意味ベースAST(
RestrictionAst/RestrictionAstType)と、Restriction ⇄ AST の相互変換・可読表示を追加 - 属性型ごとの許可AST種別や choice/label 名一覧を返すカタログ出力(
get_attribute_restriction_catalog)を追加 annotation_specsの型情報(TypedDict)を拡充し、関連テストを追加・既存テスト方針(例外メッセージ一致検証をしない)に合わせて更新
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/util/test_page.py | pytest.raises(..., match=...) をやめ、例外型のみ検証するテスト方針に合わせて修正 |
| tests/util/test_attribute_restrictions.py | AST round-trip、妥当性、可読表示、catalog出力のテストを追加 |
| tests/util/test_annotation_specs.py | AttributeChoice 型導入に合わせてテストの型注釈を更新 |
| annofabapi/util/attribute_restrictions.py | RestrictionAst/カタログ/相互変換/可読表示などの主要機能を実装 |
| annofabapi/util/annotation_specs.py | TypedDict導入と AnnotationSpecsAccessor の型付け強化 |
| AGENTS.md | エージェント実行環境・進め方ガイドを追加 |
| .github/copilot-instructions.md | 参照先を AGENTS.md / .agents/skills/ に集約 |
| .codex/config.toml | Codex用のsandbox/approval設定を追加 |
| .agents/skills/test-writing/SKILL.md | テスト方針(例外メッセージ一致検証しない等)を明文化 |
| .agents/skills/python-coding-style/SKILL.md | Pythonコーディングスタイル(match推奨等)を明文化 |
概要
変更内容
動作確認