Skip to content

Commit 38124a3

Browse files
Merge pull request #2499 from VWS-Python/strict-mypy-plugin
Use new mypy plugin for strict kwargs
2 parents 18a51b9 + b1adac2 commit 38124a3

File tree

7 files changed

+40
-25
lines changed

7 files changed

+40
-25
lines changed

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
# This method of getting the release from the version goes hand in hand with
4040
# the ``post-release`` versioning scheme chosen in the ``setuptools-scm``
4141
# configuration.
42-
release = version.split(".post")[0]
42+
release = version.split(sep=".post")[0]
4343

4444

4545
project_metadata = importlib.metadata.metadata(distribution_name=project)

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ optional-dependencies.dev = [
4949
"furo==2024.8.6",
5050
"interrogate==1.7.0",
5151
"mypy[faster-cache]==1.14.0",
52+
"mypy-strict-kwargs==2024.12.24",
5253
"pre-commit==4.0.1",
5354
"pydocstyle==6.3",
5455
"pyenchant==3.3.0rc1",
@@ -334,6 +335,9 @@ strict = true
334335
files = [ "." ]
335336
exclude = [ "build" ]
336337
follow_untyped_imports = true
338+
plugins = [
339+
"mypy_strict_kwargs",
340+
]
337341

338342
[tool.pyright]
339343

src/vws/exceptions/vws_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def target_name(self) -> str:
154154
"""
155155
response_body = self.response.request_body or b""
156156
request_json = json.loads(s=response_body)
157-
return str(request_json["name"])
157+
return str(object=request_json["name"])
158158

159159

160160
@beartype

src/vws/vws.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def add_target(
322322
content_type="application/json",
323323
)
324324

325-
return str(json.loads(s=response.text)["target_id"])
325+
return str(object=json.loads(s=response.text)["target_id"])
326326

327327
def get_target_record(self, target_id: str) -> TargetStatusAndRecord:
328328
"""Get a given target's target record from the Target Management

tests/test_cloud_reco_exceptions.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_too_many_max_results(
3333
A ``MaxNumResultsOutOfRange`` error is raised if the given
3434
``max_num_results`` is out of range.
3535
"""
36-
with pytest.raises(MaxNumResultsOutOfRangeError) as exc:
36+
with pytest.raises(expected_exception=MaxNumResultsOutOfRangeError) as exc:
3737
cloud_reco_client.query(
3838
image=high_quality_image,
3939
max_num_results=51,
@@ -43,7 +43,7 @@ def test_too_many_max_results(
4343
"Integer out of range (51) in form data part 'max_result'. "
4444
"Accepted range is from 1 to 50 (inclusive)."
4545
)
46-
assert str(exc.value) == exc.value.response.text == expected_value
46+
assert str(object=exc.value) == exc.value.response.text == expected_value
4747

4848

4949
def test_image_too_large(
@@ -54,7 +54,7 @@ def test_image_too_large(
5454
A ``RequestEntityTooLarge`` exception is raised if an image which is too
5555
large is given.
5656
"""
57-
with pytest.raises(RequestEntityTooLargeError) as exc:
57+
with pytest.raises(expected_exception=RequestEntityTooLargeError) as exc:
5858
cloud_reco_client.query(image=png_too_large)
5959

6060
assert (
@@ -92,7 +92,9 @@ def test_authentication_failure(
9292
with MockVWS() as mock:
9393
mock.add_database(database=database)
9494

95-
with pytest.raises(AuthenticationFailureError) as exc:
95+
with pytest.raises(
96+
expected_exception=AuthenticationFailureError
97+
) as exc:
9698
cloud_reco_client.query(image=high_quality_image)
9799

98100
assert exc.value.response.status_code == HTTPStatus.UNAUTHORIZED
@@ -113,7 +115,7 @@ def test_inactive_project(
113115
client_secret_key=database.client_secret_key,
114116
)
115117

116-
with pytest.raises(InactiveProjectError) as exc:
118+
with pytest.raises(expected_exception=InactiveProjectError) as exc:
117119
cloud_reco_client.query(image=high_quality_image)
118120

119121
response = exc.value.response

tests/test_vws.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ class TestAddTarget:
3030
"""
3131

3232
@staticmethod
33-
@pytest.mark.parametrize("application_metadata", [None, b"a"])
34-
@pytest.mark.parametrize("active_flag", [True, False])
33+
@pytest.mark.parametrize(
34+
argnames="application_metadata",
35+
argvalues=[None, b"a"],
36+
)
37+
@pytest.mark.parametrize(argnames="active_flag", argvalues=[True, False])
3538
def test_add_target(
3639
vws_client: VWS,
3740
image: io.BytesIO | BinaryIO,
@@ -211,7 +214,7 @@ def test_get_target_summary_report(
211214
status=TargetStatuses.SUCCESS,
212215
database_name=report.database_name,
213216
target_name=target_name,
214-
upload_date=datetime.date(2018, 4, 25),
217+
upload_date=datetime.date(year=2018, month=4, day=25),
215218
active_flag=True,
216219
tracking_rating=report.tracking_rating,
217220
total_recos=0,
@@ -511,7 +514,9 @@ def test_custom_timeout(image: io.BytesIO | BinaryIO) -> None:
511514

512515
report = vws_client.get_target_summary_report(target_id=target_id)
513516
assert report.status == TargetStatuses.PROCESSING
514-
with pytest.raises(TargetProcessingTimeoutError):
517+
with pytest.raises(
518+
expected_exception=TargetProcessingTimeoutError
519+
):
515520
vws_client.wait_for_target_processed(
516521
target_id=target_id,
517522
timeout_seconds=0.1,

tests/test_vws_exceptions.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_image_too_large(
4545
When giving an image which is too large, an ``ImageTooLarge`` exception is
4646
raised.
4747
"""
48-
with pytest.raises(ImageTooLargeError) as exc:
48+
with pytest.raises(expected_exception=ImageTooLargeError) as exc:
4949
vws_client.add_target(
5050
name="x",
5151
width=1,
@@ -63,7 +63,7 @@ def test_invalid_given_id(vws_client: VWS) -> None:
6363
causes an ``UnknownTarget`` exception to be raised.
6464
"""
6565
target_id = "12345abc"
66-
with pytest.raises(UnknownTargetError) as exc:
66+
with pytest.raises(expected_exception=UnknownTargetError) as exc:
6767
vws_client.delete_target(target_id=target_id)
6868
assert exc.value.response.status_code == HTTPStatus.NOT_FOUND
6969
assert exc.value.target_id == target_id
@@ -76,7 +76,9 @@ def test_add_bad_name(vws_client: VWS, high_quality_image: io.BytesIO) -> None:
7676
"""
7777
max_char_value = 65535
7878
bad_name = chr(max_char_value + 1)
79-
with pytest.raises(OopsAnErrorOccurredPossiblyBadNameError) as exc:
79+
with pytest.raises(
80+
expected_exception=OopsAnErrorOccurredPossiblyBadNameError
81+
) as exc:
8082
vws_client.add_target(
8183
name=bad_name,
8284
width=1,
@@ -105,7 +107,7 @@ def test_fail(high_quality_image: io.BytesIO) -> None:
105107
server_secret_key=uuid.uuid4().hex,
106108
)
107109

108-
with pytest.raises(FailError) as exc:
110+
with pytest.raises(expected_exception=FailError) as exc:
109111
vws_client.add_target(
110112
name="x",
111113
width=1,
@@ -122,7 +124,7 @@ def test_bad_image(vws_client: VWS) -> None:
122124
A ``BadImage`` exception is raised when a non-image is given.
123125
"""
124126
not_an_image = io.BytesIO(initial_bytes=b"Not an image")
125-
with pytest.raises(BadImageError) as exc:
127+
with pytest.raises(expected_exception=BadImageError) as exc:
126128
vws_client.add_target(
127129
name="x",
128130
width=1,
@@ -149,7 +151,7 @@ def test_target_name_exist(
149151
active_flag=True,
150152
application_metadata=None,
151153
)
152-
with pytest.raises(TargetNameExistError) as exc:
154+
with pytest.raises(expected_exception=TargetNameExistError) as exc:
153155
vws_client.add_target(
154156
name="x",
155157
width=1,
@@ -177,7 +179,7 @@ def test_project_inactive(
177179
server_secret_key=database.server_secret_key,
178180
)
179181

180-
with pytest.raises(ProjectInactiveError) as exc:
182+
with pytest.raises(expected_exception=ProjectInactiveError) as exc:
181183
vws_client.add_target(
182184
name="x",
183185
width=1,
@@ -205,7 +207,7 @@ def test_target_status_processing(
205207
application_metadata=None,
206208
)
207209

208-
with pytest.raises(TargetStatusProcessingError) as exc:
210+
with pytest.raises(expected_exception=TargetStatusProcessingError) as exc:
209211
vws_client.delete_target(target_id=target_id)
210212

211213
assert exc.value.response.status_code == HTTPStatus.FORBIDDEN
@@ -220,7 +222,7 @@ def test_metadata_too_large(
220222
A ``MetadataTooLarge`` exception is raised if the metadata given is too
221223
large.
222224
"""
223-
with pytest.raises(MetadataTooLargeError) as exc:
225+
with pytest.raises(expected_exception=MetadataTooLargeError) as exc:
224226
vws_client.add_target(
225227
name="x",
226228
width=1,
@@ -260,7 +262,7 @@ def test_request_time_too_skewed(
260262
# >= 1 ticks are acceptable.
261263
with (
262264
freeze_time(auto_tick_seconds=time_difference_from_now),
263-
pytest.raises(RequestTimeTooSkewedError) as exc,
265+
pytest.raises(expected_exception=RequestTimeTooSkewedError) as exc,
264266
):
265267
vws_client.get_target_record(target_id=target_id)
266268

@@ -285,7 +287,9 @@ def test_authentication_failure(
285287
with MockVWS() as mock:
286288
mock.add_database(database=database)
287289

288-
with pytest.raises(AuthenticationFailureError) as exc:
290+
with pytest.raises(
291+
expected_exception=AuthenticationFailureError
292+
) as exc:
289293
vws_client.add_target(
290294
name="x",
291295
width=1,
@@ -313,7 +317,7 @@ def test_target_status_not_success(
313317
application_metadata=None,
314318
)
315319

316-
with pytest.raises(TargetStatusNotSuccessError) as exc:
320+
with pytest.raises(expected_exception=TargetStatusNotSuccessError) as exc:
317321
vws_client.update_target(target_id=target_id)
318322

319323
assert exc.value.response.status_code == HTTPStatus.FORBIDDEN
@@ -353,7 +357,7 @@ def test_base_exception(
353357
"""
354358
``VWSException``s has a response property.
355359
"""
356-
with pytest.raises(VWSError) as exc:
360+
with pytest.raises(expected_exception=VWSError) as exc:
357361
vws_client.get_target_record(target_id="a")
358362

359363
assert exc.value.response.status_code == HTTPStatus.NOT_FOUND

0 commit comments

Comments
 (0)