Skip to content

Commit 2286e21

Browse files
Addressed typing in shape/dataset/annotation
1 parent 981dea2 commit 2286e21

File tree

7 files changed

+42
-40
lines changed

7 files changed

+42
-40
lines changed

ote_sdk/ote_sdk/entities/annotation.py

+19-18
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ def __repr__(self):
2929
return (
3030
f"{self.__class__.__name__}("
3131
f"shape={self.shape}, "
32-
f"labels={self.get_labels(True)}"
32+
f"labels={self.get_labels(include_empty=True)}"
3333
)
3434

3535
@property
36-
def shape(self):
36+
def shape(self) -> ShapeEntity:
3737
"""
3838
Returns the shape that is in the annotation
3939
"""
4040
return self.__shape
4141

4242
@shape.setter
43-
def shape(self, value):
43+
def shape(self, value) -> None:
4444
self.__shape = value
4545

4646
def get_labels(self, include_empty: bool = False) -> List[ScoredLabel]:
@@ -67,15 +67,15 @@ def get_label_ids(self, include_empty: bool = False) -> Set[ID]:
6767
if include_empty or (not label.is_empty)
6868
}
6969

70-
def append_label(self, label: ScoredLabel):
70+
def append_label(self, label: ScoredLabel) -> None:
7171
"""
7272
Appends the scored label to the annotation.
7373
7474
:param label: the scored label to be appended to the annotation
7575
"""
7676
self.__labels.append(label)
7777

78-
def set_labels(self, labels: List[ScoredLabel]):
78+
def set_labels(self, labels: List[ScoredLabel]) -> None:
7979
"""
8080
Sets the labels of the annotation to be the input of the function.
8181
@@ -86,7 +86,8 @@ def set_labels(self, labels: List[ScoredLabel]):
8686
def __eq__(self, other):
8787
if isinstance(other, Annotation):
8888
return (
89-
self.get_labels(True) == other.get_labels(True)
89+
self.get_labels(include_empty=True)
90+
== other.get_labels(include_empty=True)
9091
and self.shape == other.shape
9192
)
9293
return False
@@ -160,14 +161,14 @@ def __repr__(self):
160161
)
161162

162163
@property
163-
def id_(self):
164+
def id_(self) -> ID:
164165
"""
165166
Returns the ID of the AnnotationSceneEntity.
166167
"""
167168
return self.__id_
168169

169170
@id_.setter
170-
def id_(self, value):
171+
def id_(self, value) -> None:
171172
self.__id_ = value
172173

173174
@property
@@ -181,36 +182,36 @@ def id(self, value):
181182
self.__id_ = value
182183

183184
@property
184-
def kind(self):
185+
def kind(self) -> AnnotationSceneKind:
185186
"""
186187
Returns the AnnotationSceneKind of the AnnotationSceneEntity.
187188
"""
188189
return self.__kind
189190

190191
@kind.setter
191-
def kind(self, value):
192+
def kind(self, value) -> None:
192193
self.__kind = value
193194

194195
@property
195-
def editor_name(self):
196+
def editor_name(self) -> str:
196197
"""
197198
Returns the editor's name that made the AnnotationSceneEntity object.
198199
"""
199200
return self.__editor
200201

201202
@editor_name.setter
202-
def editor_name(self, value):
203+
def editor_name(self, value) -> None:
203204
self.__editor = value
204205

205206
@property
206-
def creation_date(self):
207+
def creation_date(self) -> datetime.datetime:
207208
"""
208209
Returns the creation date of the AnnotationSceneEntity object.
209210
"""
210211
return self.__creation_date
211212

212213
@creation_date.setter
213-
def creation_date(self, value):
214+
def creation_date(self, value) -> None:
214215
self.__creation_date = value
215216

216217
@property
@@ -231,7 +232,7 @@ def shapes(self) -> List[ShapeEntity]:
231232
"""
232233
return [annotation.shape for annotation in self.annotations]
233234

234-
def contains_any(self, labels: List[LabelEntity]):
235+
def contains_any(self, labels: List[LabelEntity]) -> bool:
235236
"""
236237
Checks whether the annotation contains any labels in the input parameter.
237238
@@ -249,13 +250,13 @@ def contains_any(self, labels: List[LabelEntity]):
249250
!= 0
250251
)
251252

252-
def append_annotation(self, annotation: Annotation):
253+
def append_annotation(self, annotation: Annotation) -> None:
253254
"""
254255
Appends the passed annotation to the list of annotations present in the AnnotationSceneEntity object.
255256
"""
256257
self.annotations.append(annotation)
257258

258-
def append_annotations(self, annotations: List[Annotation]):
259+
def append_annotations(self, annotations: List[Annotation]) -> None:
259260
"""
260261
Adds a list of annotations to the annotation scene.
261262
"""
@@ -272,7 +273,7 @@ def get_labels(self, include_empty: bool = False) -> List[LabelEntity]:
272273

273274
labels: Dict[str, LabelEntity] = {}
274275
for annotation in self.annotations:
275-
for label in annotation.get_labels(include_empty):
276+
for label in annotation.get_labels(include_empty=include_empty):
276277
id_ = label.id_
277278
if id_ not in labels:
278279
labels[id_] = label.get_label()

ote_sdk/ote_sdk/entities/datasets.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def purpose(self) -> DatasetPurpose:
137137
return self._purpose
138138

139139
@purpose.setter
140-
def purpose(self, value: DatasetPurpose):
140+
def purpose(self, value: DatasetPurpose) -> None:
141141
self._purpose = value
142142

143143
def _fetch(self, key):
@@ -306,7 +306,7 @@ def get_subset(self, subset: Subset) -> "DatasetEntity":
306306
)
307307
return dataset
308308

309-
def remove(self, item: DatasetItemEntity):
309+
def remove(self, item: DatasetItemEntity) -> None:
310310
"""
311311
Remove an item from the items.
312312
This function calls remove_at_indices function.
@@ -339,14 +339,14 @@ def append(self, item: DatasetItemEntity) -> None:
339339
raise ValueError("Media in dataset item cannot be None")
340340
self._items.append(item)
341341

342-
def sort_items(self):
342+
def sort_items(self) -> None:
343343
"""
344344
Order the dataset items. Does nothing here, but may be overrided in child classes.
345345
346346
:return: None
347347
"""
348348

349-
def remove_at_indices(self, indices: List[int]):
349+
def remove_at_indices(self, indices: List[int]) -> None:
350350
"""
351351
Delete items based on the `indices`.
352352

ote_sdk/ote_sdk/entities/shapes/ellipse.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __hash__(self):
8181
return hash(str(self))
8282

8383
@property
84-
def width(self):
84+
def width(self) -> float:
8585
"""
8686
Returns the width of the ellipse. (x-axis)
8787
@@ -96,7 +96,7 @@ def width(self):
9696
return self.x2 - self.x1
9797

9898
@property
99-
def height(self):
99+
def height(self) -> float:
100100
"""
101101
Returns the height of the ellipse. (y-axis)
102102
@@ -111,14 +111,14 @@ def height(self):
111111
return self.y2 - self.y1
112112

113113
@property
114-
def x_center(self):
114+
def x_center(self) -> float:
115115
"""
116116
Returns the x coordinate in the center of the ellipse.
117117
"""
118118
return self.x1 + self.width / 2
119119

120120
@property
121-
def y_center(self):
121+
def y_center(self) -> float:
122122
"""
123123
Returns the y coordinate in the center of the ellipse.
124124
"""

ote_sdk/ote_sdk/entities/shapes/polygon.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def normalize_wrt_roi(self, roi_shape: Rectangle) -> "Point":
5555
y1 = roi_shape.y1
5656
return Point(x=self.x * width + x1, y=self.y * height + y1)
5757

58-
def denormalize_wrt_roi_shape(self, roi_shape: Rectangle):
58+
def denormalize_wrt_roi_shape(self, roi_shape: Rectangle) -> "Point":
5959
"""
6060
The inverse of normalize_wrt_roi_shape.
6161
Transforming Polygon from the normalized coordinate system to the `roi` coordinate system.

ote_sdk/ote_sdk/entities/shapes/rectangle.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ def clip_to_visible_region(self) -> "Rectangle":
101101
x2 = min(max(0.0, self.x2), 1.0)
102102
y2 = min(max(0.0, self.y2), 1.0)
103103

104-
return Rectangle(x1, y1, x2, y2, self.modification_date)
104+
return Rectangle(
105+
x1=x1, y1=y1, x2=x2, y2=y2, modification_date=self.modification_date
106+
)
105107

106108
def normalize_wrt_roi_shape(self, roi_shape: "Rectangle") -> "Rectangle":
107109
"""
@@ -230,7 +232,7 @@ def is_full_box(rectangle: ShapeEntity) -> bool:
230232
return True
231233
return False
232234

233-
def crop_numpy_array(self, data: np.ndarray):
235+
def crop_numpy_array(self, data: np.ndarray) -> np.ndarray:
234236
"""
235237
Crop the given Numpy array to the region of interest represented by this
236238
rectangle.
@@ -252,7 +254,7 @@ def crop_numpy_array(self, data: np.ndarray):
252254
return data[y1:y2, x1:x2, ::]
253255

254256
@property
255-
def width(self):
257+
def width(self) -> float:
256258
"""
257259
Returns the width of the rectangle. (x-axis)
258260
@@ -267,7 +269,7 @@ def width(self):
267269
return self.x2 - self.x1
268270

269271
@property
270-
def height(self):
272+
def height(self) -> float:
271273
"""
272274
Returns the height of the rectangle. (y-axis)
273275
@@ -282,7 +284,7 @@ def height(self):
282284
return self.y2 - self.y1
283285

284286
@property
285-
def diagonal(self):
287+
def diagonal(self) -> float:
286288
"""
287289
Returns the diagonal size/hypotenuse of the rectangle. (x-axis)
288290

ote_sdk/ote_sdk/entities/shapes/shape.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, shape_type: ShapeType):
4040
self._type = shape_type
4141

4242
@property
43-
def type(self):
43+
def type(self) -> ShapeType:
4444
"""
4545
Get the type of Shape that this Shape represents
4646
"""

ote_sdk/ote_sdk/tests/entities/shapes/test_rectangle.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ def test_rectangle_optional_parameters(self):
118118
Instance of Rectangle class
119119
120120
<b>Expected results:</b>
121-
Test passes if Rectangle instance has expected labels and modification attributes specified during Rectangle
121+
Test passes if Rectangle instance has expected modification attributes specified during Rectangle
122122
class object initiation with optional parameters
123123
124124
<b>Steps</b>
125-
1. Compare default label Rectangle instance attribute with expected value
125+
1. Compare default Rectangle instance attribute with expected value
126126
2. Check type of default modification_date Rectangle instance attribute
127-
3. Compare specified label Rectangle instance attribute with expected value
127+
3. Compare specified Rectangle instance attribute with expected value
128128
4. Compare specified modification_date Rectangle instance attribute with expected value
129129
"""
130130
# Checking default values of optional parameters
@@ -221,8 +221,7 @@ def test_rectangle_eq(self):
221221
1. Check __eq__ method for instances of Rectangle class with equal parameters
222222
2. Check __eq__ method for different instances of Rectangle class
223223
3. Check __eq__ method for instances of different classes
224-
4. Check __eq__ method for instances of Rectangle class with unequal labels attribute
225-
5. Check __eq__ method for instances of Rectangle class with unequal x1, y1, x2, y2 and
224+
4. Check __eq__ method for instances of Rectangle class with unequal x1, y1, x2, y2 and
226225
modification_date attributes
227226
"""
228227
rectangle = self.vertical_rectangle()
@@ -233,7 +232,7 @@ def test_rectangle_eq(self):
233232
assert rectangle != self.horizontal_rectangle()
234233
# Check for different types branch
235234
assert rectangle != str
236-
# Check for unequal labels parameters. Expected that different labels are not affecting equality
235+
237236
assert rectangle == equal_rectangle
238237
# Check for instances with unequal parameters combinations
239238
# Generating all possible scenarios of parameter values submission
@@ -458,7 +457,7 @@ def test_rectangle_generate_full_box(self):
458457
(x1=0.0, y1=0.0, x2=1.0, y2=1.0)
459458
460459
<b>Steps</b>
461-
1. Check generate_full_box method for Rectangle instance with no labels specified
460+
1. Check generate_full_box method for Rectangle instance
462461
"""
463462
full_box = Rectangle.generate_full_box()
464463
assert full_box.type == ShapeType.RECTANGLE

0 commit comments

Comments
 (0)