Skip to content

Commit 2896662

Browse files
committed
Return early for empty response.
1 parent 7aa42be commit 2896662

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

vision/google/cloud/vision/image.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,17 @@ def _entity_from_response_type(feature_type, results):
220220

221221
detected_objects = []
222222
feature_key = _REVERSE_TYPES[feature_type]
223-
annotations = results.get(feature_key, [])
223+
annotations = results.get(feature_key, ())
224+
if not annotations:
225+
return []
224226

225227
if feature_type == _FACE_DETECTION:
226228
detected_objects.extend(
227229
Face.from_api_repr(face) for face in annotations)
228-
elif feature_type == _IMAGE_PROPERTIES and annotations:
230+
elif feature_type == _IMAGE_PROPERTIES:
229231
detected_objects.append(
230232
ImagePropertiesAnnotation.from_api_repr(annotations))
231-
elif feature_type == _SAFE_SEARCH_DETECTION and annotations:
233+
elif feature_type == _SAFE_SEARCH_DETECTION:
232234
detected_objects.append(
233235
SafeSearchAnnotation.from_api_repr(annotations))
234236
else:

0 commit comments

Comments
 (0)