Skip to content

Commit 1b2001e

Browse files
adamtheturtleclaude
andcommitted
Fix integer timeouts failing at request time
_target_api_request used plain @beartype which rejects int for float, while VWS.__init__ used is_pep484_tower=True which accepts it. This caused integer timeouts to pass construction but fail on first request. Enable is_pep484_tower on _target_api_request and CloudRecoService too. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8217323 commit 1b2001e

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

src/vws/query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from urllib.parse import urljoin
99

1010
import requests
11-
from beartype import beartype
11+
from beartype import BeartypeConf, beartype
1212
from urllib3.filepost import encode_multipart_formdata
1313
from vws_auth_tools import authorization_header, rfc_1123_date
1414

@@ -40,7 +40,7 @@ def _get_image_data(image: _ImageType) -> bytes:
4040
return image_data
4141

4242

43-
@beartype
43+
@beartype(conf=BeartypeConf(is_pep484_tower=True))
4444
class CloudRecoService:
4545
"""An interface to the Vuforia Cloud Recognition Web APIs."""
4646

src/vws/vws.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _get_image_data(image: _ImageType) -> bytes:
5858
return image_data
5959

6060

61-
@beartype
61+
@beartype(conf=BeartypeConf(is_pep484_tower=True))
6262
def _target_api_request(
6363
*,
6464
content_type: str,

tests/test_query.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,35 @@ def test_custom_timeout(image: io.BytesIO | BinaryIO) -> None:
9393
matches = cloud_reco_client.query(image=image)
9494
assert len(matches) == 1
9595

96+
@staticmethod
97+
def test_custom_timeout_int(image: io.BytesIO | BinaryIO) -> None:
98+
"""It is possible to set a custom request timeout as an int."""
99+
with MockVWS() as mock:
100+
database = VuforiaDatabase()
101+
mock.add_database(database=database)
102+
vws_client = VWS(
103+
server_access_key=database.server_access_key,
104+
server_secret_key=database.server_secret_key,
105+
)
106+
custom_timeout = 60
107+
cloud_reco_client = CloudRecoService(
108+
client_access_key=database.client_access_key,
109+
client_secret_key=database.client_secret_key,
110+
request_timeout_seconds=custom_timeout,
111+
)
112+
assert cloud_reco_client.request_timeout_seconds == custom_timeout
113+
114+
target_id = vws_client.add_target(
115+
name="x",
116+
width=1,
117+
image=image,
118+
active_flag=True,
119+
application_metadata=None,
120+
)
121+
vws_client.wait_for_target_processed(target_id=target_id)
122+
matches = cloud_reco_client.query(image=image)
123+
assert len(matches) == 1
124+
96125
@staticmethod
97126
def test_custom_timeout_tuple(image: io.BytesIO | BinaryIO) -> None:
98127
"""It is possible to set separate connect and read timeouts."""

tests/test_vws.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,28 @@ def test_custom_timeout(image: io.BytesIO | BinaryIO) -> None:
135135
application_metadata=None,
136136
)
137137

138+
@staticmethod
139+
def test_custom_timeout_int(image: io.BytesIO | BinaryIO) -> None:
140+
"""It is possible to set a custom request timeout as an int."""
141+
with MockVWS() as mock:
142+
database = VuforiaDatabase()
143+
mock.add_database(database=database)
144+
custom_timeout = 60
145+
vws_client = VWS(
146+
server_access_key=database.server_access_key,
147+
server_secret_key=database.server_secret_key,
148+
request_timeout_seconds=custom_timeout,
149+
)
150+
assert vws_client.request_timeout_seconds == custom_timeout
151+
152+
vws_client.add_target(
153+
name="x",
154+
width=1,
155+
image=image,
156+
active_flag=True,
157+
application_metadata=None,
158+
)
159+
138160
@staticmethod
139161
def test_custom_timeout_tuple(image: io.BytesIO | BinaryIO) -> None:
140162
"""It is possible to set separate connect and read timeouts."""

0 commit comments

Comments
 (0)