Skip to content

Commit 44e05c4

Browse files
committed
Added from_dict method to the FeatureSchemaAttribute data class
1 parent d4d9896 commit 44e05c4

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

libs/labelbox/src/labelbox/schema/ontology.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,7 @@ def from_dict(cls, dictionary: Dict[str, Any]) -> Dict[str, Any]:
123123
],
124124
color=dictionary["color"],
125125
attributes=[
126-
FeatureSchemaAttribute(
127-
attributeName=attr["attributeName"],
128-
attributeValue=attr["attributeValue"],
129-
)
126+
FeatureSchemaAttribute.from_dict(attr)
130127
for attr in dictionary.get("attributes", []) or []
131128
]
132129
if dictionary.get("attributes")

libs/labelbox/src/labelbox/schema/tool_building/classification.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ def from_dict(cls, dictionary: Dict[str, Any]) -> "Classification":
114114
feature_schema_id=dictionary.get("featureSchemaId", None),
115115
scope=cls.Scope(dictionary.get("scope", cls.Scope.GLOBAL)),
116116
attributes=[
117-
FeatureSchemaAttribute(
118-
attributeName=attr["attributeName"],
119-
attributeValue=attr["attributeValue"],
120-
)
117+
FeatureSchemaAttribute.from_dict(attr)
121118
for attr in dictionary.get("attributes", []) or []
122119
]
123120
if dictionary.get("attributes")

libs/labelbox/src/labelbox/schema/tool_building/types.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from dataclasses import dataclass
77

8+
from typing import Any, Dict, List
9+
810

911
@dataclass
1012
class FeatureSchemaAttribute:
@@ -17,6 +19,13 @@ def asdict(self):
1719
"attributeValue": self.attributeValue,
1820
}
1921

22+
@classmethod
23+
def from_dict(cls, dictionary: Dict[str, Any]) -> "FeatureSchemaAttribute":
24+
return cls(
25+
attributeName=dictionary["attributeName"],
26+
attributeValue=dictionary["attributeValue"],
27+
)
28+
2029

2130
FeatureSchemaAttribute = Annotated[FeatureSchemaAttribute, Field()]
2231

0 commit comments

Comments
 (0)