Skip to content

Commit 5698c09

Browse files
fix: return list from upload() in both single and directory cases
Per review feedback on PR #502: wrap the single-file return in a list so upload() always returns list[dict] regardless of input type. - single file: return [single_upload_result] instead of single_upload_result - directory: unchanged (already returns list) - update docstring to reflect consistent list return type - update tests in test_project.py and test_queries.py accordingly
1 parent 48a7ce1 commit 5698c09

3 files changed

Lines changed: 31 additions & 24 deletions

File tree

‎roboflow/core/project.py‎

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,11 @@ def upload(
410410
Example: {"camera_id": "cam001", "location": "warehouse"}
411411
412412
Returns:
413-
For a single image: the dict returned by ``single_upload`` (keys: ``image``,
414-
``annotation``, ``upload_time``, ``annotation_time``, ``upload_retry_attempts``,
415-
``annotation_upload_retry_attempts``). For a directory: a list of such dicts,
416-
one per successfully uploaded image. Skipped (non-image) files are excluded.
413+
A list of result dicts (one per successfully uploaded image), regardless of
414+
whether a single file or a directory was provided. Each dict is the return
415+
value of ``single_upload`` (keys: ``image``, ``annotation``, ``upload_time``,
416+
``annotation_time``, ``upload_retry_attempts``, ``annotation_upload_retry_attempts``).
417+
Skipped (non-image) files in directory mode are excluded from the list.
417418
418419
Example:
419420
>>> import roboflow
@@ -451,19 +452,21 @@ def upload(
451452
)
452453
)
453454

454-
return self.single_upload(
455-
image_path=image_path,
456-
annotation_path=annotation_path,
457-
hosted_image=hosted_image,
458-
image_id=image_id,
459-
split=split,
460-
num_retry_uploads=num_retry_uploads,
461-
batch_name=batch_name,
462-
tag_names=tag_names,
463-
is_prediction=is_prediction,
464-
metadata=metadata,
465-
**kwargs,
466-
)
455+
return [
456+
self.single_upload(
457+
image_path=image_path,
458+
annotation_path=annotation_path,
459+
hosted_image=hosted_image,
460+
image_id=image_id,
461+
split=split,
462+
num_retry_uploads=num_retry_uploads,
463+
batch_name=batch_name,
464+
tag_names=tag_names,
465+
is_prediction=is_prediction,
466+
metadata=metadata,
467+
**kwargs,
468+
)
469+
]
467470

468471
else:
469472
results = []

‎tests/test_project.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_upload_raises_upload_annotation_error(self):
157157
self.assertEqual(str(error.exception), "Image was already annotated.")
158158

159159
def test_upload_single_file_returns_result(self):
160-
"""upload() should return the single_upload result dict for a single file (#254)."""
160+
"""upload() should return a list with the single_upload result dict for a single file (#254)."""
161161
image_id = "test-upload-id"
162162

163163
responses.add(
@@ -169,10 +169,13 @@ def test_upload_single_file_returns_result(self):
169169

170170
result = self.project.upload("tests/images/rabbit.JPG")
171171

172-
self.assertIsInstance(result, dict)
173-
self.assertEqual(result["image"]["id"], image_id)
174-
self.assertIn("upload_time", result)
175-
self.assertIn("upload_retry_attempts", result)
172+
self.assertIsInstance(result, list)
173+
self.assertEqual(len(result), 1)
174+
entry = result[0]
175+
self.assertIsInstance(entry, dict)
176+
self.assertEqual(entry["image"]["id"], image_id)
177+
self.assertIn("upload_time", entry)
178+
self.assertIn("upload_retry_attempts", entry)
176179

177180
def test_upload_directory_returns_list_of_results(self):
178181
"""upload() should return a list of single_upload results for a directory (#254)."""

‎tests/test_queries.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ def test_project_methods(self):
6060
self.assertEqual(len(version_information), 2)
6161
self.assertIsNone(print_versions)
6262
self.assertTrue(all(map(lambda x: isinstance(x, Version), list_versions)))
63-
self.assertIsInstance(upload, dict)
64-
self.assertEqual(upload["image"]["id"], "hbALkCFdNr9rssgOUXug")
63+
self.assertIsInstance(upload, list)
64+
self.assertEqual(len(upload), 1)
65+
self.assertEqual(upload[0]["image"]["id"], "hbALkCFdNr9rssgOUXug")
6566

6667
@ordered
6768
def test_version_fields(self):

0 commit comments

Comments
 (0)