Skip to content

Commit e9d7d2d

Browse files
committed
型の判定
1 parent 9d569c3 commit e9d7d2d

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

annofabapi/pydantic_models/full_annotation_data_classification.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ def to_json(self) -> str:
4646
@classmethod
4747
def from_json(cls, json_str: str) -> Optional[Self]:
4848
"""Create an instance of FullAnnotationDataClassification from a JSON string"""
49-
return cls.from_dict(json.loads(json_str))
49+
result = cls.from_dict(json.loads(json_str))
50+
if result.type != "Classification":
51+
raise ValueError("Invalid type")
52+
return result
5053

5154
def to_dict(self) -> Dict[str, Any]:
5255
"""Return the dictionary representation of the model using alias.

annofabapi/pydantic_models/full_annotation_data_segmentation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ def to_json(self) -> str:
4949
@classmethod
5050
def from_json(cls, json_str: str) -> Optional[Self]:
5151
"""Create an instance of FullAnnotationDataSegmentation from a JSON string"""
52-
return cls.from_dict(json.loads(json_str))
52+
result = cls.from_dict(json.loads(json_str))
53+
if result.type != "Segmentation":
54+
raise ValueError("Invalid type")
55+
return result
5356

5457
def to_dict(self) -> Dict[str, Any]:
5558
"""Return the dictionary representation of the model using alias.

annofabapi/pydantic_models/full_annotation_data_segmentation_v2.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ def to_json(self) -> str:
4949
@classmethod
5050
def from_json(cls, json_str: str) -> Optional[Self]:
5151
"""Create an instance of FullAnnotationDataSegmentationV2 from a JSON string"""
52-
return cls.from_dict(json.loads(json_str))
52+
result = cls.from_dict(json.loads(json_str))
53+
if result.type != "SegmentationV2":
54+
raise ValueError("Invalid type")
55+
return result
5356

5457
def to_dict(self) -> Dict[str, Any]:
5558
"""Return the dictionary representation of the model using alias.

0 commit comments

Comments
 (0)