Skip to content

Commit 50b63b1

Browse files
committed
Accept all IO[bytes] as image type
1 parent dc729a7 commit 50b63b1

File tree

6 files changed

+32
-36
lines changed

6 files changed

+32
-36
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ Changelog
44
Next
55
----
66

7-
2025.03.10.1
8-
------------
7+
* Be more flexible in the types of images accepted.
98

109
2025.03.10
1110
----------

src/vws/query.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
"""
44

55
import datetime
6-
import io
76
import json
87
from http import HTTPMethod, HTTPStatus
9-
from typing import Any, BinaryIO
8+
from typing import IO, Any
109
from urllib.parse import urljoin
1110

1211
import requests
@@ -29,7 +28,7 @@
2928
from vws.reports import QueryResult, TargetData
3029
from vws.response import Response
3130

32-
_ImageType = io.BytesIO | BinaryIO
31+
_ImageType = IO[bytes]
3332

3433

3534
@beartype

src/vws/vws.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
"""
44

55
import base64
6-
import io
76
import json
87
import time
98
from datetime import date
109
from http import HTTPMethod, HTTPStatus
11-
from typing import BinaryIO
10+
from typing import IO
1211
from urllib.parse import urljoin
1312

1413
import requests
@@ -47,7 +46,7 @@
4746
)
4847
from vws.response import Response
4948

50-
_ImageType = io.BytesIO | BinaryIO
49+
_ImageType = IO[bytes]
5150

5251

5352
@beartype

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import io
66
from collections.abc import Generator
77
from pathlib import Path
8-
from typing import BinaryIO, Literal
8+
from typing import IO, BinaryIO, Literal
99

1010
import pytest
1111
from mock_vws import MockVWS
@@ -70,7 +70,7 @@ def image(
7070
request: pytest.FixtureRequest,
7171
high_quality_image: io.BytesIO,
7272
image_file: BinaryIO,
73-
) -> io.BytesIO | BinaryIO:
73+
) -> IO[bytes]:
7474
"""
7575
An image in any of the types that the API accepts.
7676
"""

tests/test_query.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
Tests for the ``CloudRecoService`` querying functionality.
33
"""
44

5-
import io
65
import uuid
7-
from typing import BinaryIO
6+
from typing import IO
87

98
from mock_vws import MockVWS
109
from mock_vws.database import VuforiaDatabase
@@ -21,7 +20,7 @@ class TestQuery:
2120
@staticmethod
2221
def test_no_matches(
2322
cloud_reco_client: CloudRecoService,
24-
image: io.BytesIO | BinaryIO,
23+
image: IO[bytes],
2524
) -> None:
2625
"""
2726
An empty list is returned if there are no matches.
@@ -33,7 +32,7 @@ def test_no_matches(
3332
def test_match(
3433
vws_client: VWS,
3534
cloud_reco_client: CloudRecoService,
36-
image: io.BytesIO | BinaryIO,
35+
image: IO[bytes],
3736
) -> None:
3837
"""
3938
Details of matching targets are returned.
@@ -56,7 +55,7 @@ class TestCustomBaseVWQURL:
5655
"""
5756

5857
@staticmethod
59-
def test_custom_base_url(image: io.BytesIO | BinaryIO) -> None:
58+
def test_custom_base_url(image: IO[bytes]) -> None:
6059
"""
6160
It is possible to use query a target to a database under a custom VWQ
6261
URL.
@@ -101,7 +100,7 @@ class TestMaxNumResults:
101100
def test_default(
102101
vws_client: VWS,
103102
cloud_reco_client: CloudRecoService,
104-
image: io.BytesIO | BinaryIO,
103+
image: IO[bytes],
105104
) -> None:
106105
"""
107106
By default the maximum number of results is 1.
@@ -129,7 +128,7 @@ def test_default(
129128
def test_custom(
130129
vws_client: VWS,
131130
cloud_reco_client: CloudRecoService,
132-
image: io.BytesIO | BinaryIO,
131+
image: IO[bytes],
133132
) -> None:
134133
"""
135134
It is possible to set a custom ``max_num_results``.
@@ -175,7 +174,7 @@ class TestIncludeTargetData:
175174
def test_default(
176175
vws_client: VWS,
177176
cloud_reco_client: CloudRecoService,
178-
image: io.BytesIO | BinaryIO,
177+
image: IO[bytes],
179178
) -> None:
180179
"""
181180
By default, target data is only returned in the top match.
@@ -207,7 +206,7 @@ def test_default(
207206
def test_top(
208207
vws_client: VWS,
209208
cloud_reco_client: CloudRecoService,
210-
image: io.BytesIO | BinaryIO,
209+
image: IO[bytes],
211210
) -> None:
212211
"""
213212
When ``CloudRecoIncludeTargetData.TOP`` is given, target data is only
@@ -241,7 +240,7 @@ def test_top(
241240
def test_none(
242241
vws_client: VWS,
243242
cloud_reco_client: CloudRecoService,
244-
image: io.BytesIO | BinaryIO,
243+
image: IO[bytes],
245244
) -> None:
246245
"""
247246
When ``CloudRecoIncludeTargetData.NONE`` is given, target data is not
@@ -275,7 +274,7 @@ def test_none(
275274
def test_all(
276275
vws_client: VWS,
277276
cloud_reco_client: CloudRecoService,
278-
image: io.BytesIO | BinaryIO,
277+
image: IO[bytes],
279278
) -> None:
280279
"""
281280
When ``CloudRecoIncludeTargetData.ALL`` is given, target data is

tests/test_vws.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import io
88
import secrets
99
import uuid
10-
from typing import BinaryIO
10+
from typing import IO
1111

1212
import pytest
1313
from freezegun import freeze_time
@@ -37,7 +37,7 @@ class TestAddTarget:
3737
@pytest.mark.parametrize(argnames="active_flag", argvalues=[True, False])
3838
def test_add_target(
3939
vws_client: VWS,
40-
image: io.BytesIO | BinaryIO,
40+
image: IO[bytes],
4141
application_metadata: bytes | None,
4242
cloud_reco_client: CloudRecoService,
4343
*,
@@ -81,7 +81,7 @@ def test_add_target(
8181
@staticmethod
8282
def test_add_two_targets(
8383
vws_client: VWS,
84-
image: io.BytesIO | BinaryIO,
84+
image: IO[bytes],
8585
) -> None:
8686
"""No exception is raised when adding two targets with different names.
8787
@@ -103,7 +103,7 @@ class TestCustomBaseVWSURL:
103103
"""
104104

105105
@staticmethod
106-
def test_custom_base_url(image: io.BytesIO | BinaryIO) -> None:
106+
def test_custom_base_url(image: IO[bytes]) -> None:
107107
"""
108108
It is possible to use add a target to a database under a custom VWS
109109
URL.
@@ -135,7 +135,7 @@ class TestListTargets:
135135
@staticmethod
136136
def test_list_targets(
137137
vws_client: VWS,
138-
image: io.BytesIO | BinaryIO,
138+
image: IO[bytes],
139139
) -> None:
140140
"""
141141
It is possible to get a list of target IDs.
@@ -165,7 +165,7 @@ class TestDelete:
165165
@staticmethod
166166
def test_delete_target(
167167
vws_client: VWS,
168-
image: io.BytesIO | BinaryIO,
168+
image: IO[bytes],
169169
) -> None:
170170
"""
171171
It is possible to delete a target.
@@ -192,7 +192,7 @@ class TestGetTargetSummaryReport:
192192
@staticmethod
193193
def test_get_target_summary_report(
194194
vws_client: VWS,
195-
image: io.BytesIO | BinaryIO,
195+
image: IO[bytes],
196196
) -> None:
197197
"""
198198
Details of a target are returned by ``get_target_summary_report``.
@@ -294,7 +294,7 @@ class TestGetTargetRecord:
294294
@staticmethod
295295
def test_get_target_record(
296296
vws_client: VWS,
297-
image: io.BytesIO | BinaryIO,
297+
image: IO[bytes],
298298
) -> None:
299299
"""
300300
Details of a target are returned by ``get_target_record``.
@@ -369,7 +369,7 @@ class TestWaitForTargetProcessed:
369369
@staticmethod
370370
def test_wait_for_target_processed(
371371
vws_client: VWS,
372-
image: io.BytesIO | BinaryIO,
372+
image: IO[bytes],
373373
) -> None:
374374
"""
375375
It is possible to wait until a target is processed.
@@ -389,7 +389,7 @@ def test_wait_for_target_processed(
389389

390390
@staticmethod
391391
def test_default_seconds_between_requests(
392-
image: io.BytesIO | BinaryIO,
392+
image: IO[bytes],
393393
) -> None:
394394
"""
395395
By default, 0.2 seconds are waited between polling requests.
@@ -441,7 +441,7 @@ def test_default_seconds_between_requests(
441441

442442
@staticmethod
443443
def test_custom_seconds_between_requests(
444-
image: io.BytesIO | BinaryIO,
444+
image: IO[bytes],
445445
) -> None:
446446
"""
447447
It is possible to customize the time waited between polling requests.
@@ -492,7 +492,7 @@ def test_custom_seconds_between_requests(
492492
assert report.request_usage == expected_requests
493493

494494
@staticmethod
495-
def test_custom_timeout(image: io.BytesIO | BinaryIO) -> None:
495+
def test_custom_timeout(image: IO[bytes]) -> None:
496496
"""
497497
It is possible to set a maximum timeout.
498498
"""
@@ -538,7 +538,7 @@ class TestGetDuplicateTargets:
538538
@staticmethod
539539
def test_get_duplicate_targets(
540540
vws_client: VWS,
541-
image: io.BytesIO | BinaryIO,
541+
image: IO[bytes],
542542
) -> None:
543543
"""
544544
It is possible to get the IDs of similar targets.
@@ -572,7 +572,7 @@ class TestUpdateTarget:
572572
@staticmethod
573573
def test_update_target(
574574
vws_client: VWS,
575-
image: io.BytesIO | BinaryIO,
575+
image: IO[bytes],
576576
different_high_quality_image: io.BytesIO,
577577
cloud_reco_client: CloudRecoService,
578578
) -> None:
@@ -633,7 +633,7 @@ def test_update_target(
633633
@staticmethod
634634
def test_no_fields_given(
635635
vws_client: VWS,
636-
image: io.BytesIO | BinaryIO,
636+
image: IO[bytes],
637637
) -> None:
638638
"""
639639
It is possible to give no update fields.

0 commit comments

Comments
 (0)