Skip to content

Commit a139fa3

Browse files
Merge pull request #2327 from VWS-Python/more-kwargs
Use more keyword arguments - better errors from type checkers
2 parents b16413a + bbae552 commit a139fa3

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

src/vws/exceptions/vws_exceptions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def target_id(self) -> str:
2424
"""
2525
The unknown target ID.
2626
"""
27-
path = urlparse(self.response.url).path
27+
path = urlparse(url=self.response.url).path
2828
# Every HTTP path which can raise this error is in the format
2929
# `/something/{target_id}`.
3030
return path.split(sep="/", maxsplit=2)[-1]
@@ -75,7 +75,7 @@ def target_id(self) -> str:
7575
"""
7676
The processing target ID.
7777
"""
78-
path = urlparse(self.response.url).path
78+
path = urlparse(url=self.response.url).path
7979
# Every HTTP path which can raise this error is in the format
8080
# `/something/{target_id}`.
8181
return path.split(sep="/", maxsplit=2)[-1]
@@ -178,7 +178,7 @@ def target_id(self) -> str:
178178
"""
179179
The unknown target ID.
180180
"""
181-
path = urlparse(self.response.url).path
181+
path = urlparse(url=self.response.url).path
182182
# Every HTTP path which can raise this error is in the format
183183
# `/something/{target_id}`.
184184
return path.split(sep="/", maxsplit=2)[-1]

src/vws/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def query(
186186
metadata = target_data_dict["application_metadata"]
187187
timestamp_string = target_data_dict["target_timestamp"]
188188
target_timestamp = datetime.datetime.fromtimestamp(
189-
timestamp_string,
189+
timestamp=timestamp_string,
190190
tz=datetime.UTC,
191191
)
192192
target_data = TargetData(

src/vws/vws.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def add_target(
316316
expected_result_code="TargetCreated",
317317
)
318318

319-
return str(json.loads(response.text)["target_id"])
319+
return str(json.loads(s=response.text)["target_id"])
320320

321321
def get_target_record(self, target_id: str) -> TargetStatusAndRecord:
322322
"""
@@ -354,7 +354,7 @@ def get_target_record(self, target_id: str) -> TargetStatusAndRecord:
354354
)
355355

356356
result_data = json.loads(s=response.text)
357-
status = TargetStatuses(result_data["status"])
357+
status = TargetStatuses(value=result_data["status"])
358358
target_record_dict = dict(result_data["target_record"])
359359
target_record = TargetRecord(
360360
target_id=target_record_dict["target_id"],
@@ -449,7 +449,7 @@ def list_targets(self) -> list[str]:
449449
expected_result_code="Success",
450450
)
451451

452-
return list(json.loads(response.text)["results"])
452+
return list(json.loads(s=response.text)["results"])
453453

454454
def get_target_summary_report(self, target_id: str) -> TargetSummaryReport:
455455
"""
@@ -486,9 +486,9 @@ def get_target_summary_report(self, target_id: str) -> TargetSummaryReport:
486486
expected_result_code="Success",
487487
)
488488

489-
result_data = dict(json.loads(response.text))
489+
result_data = dict(json.loads(s=response.text))
490490
return TargetSummaryReport(
491-
status=TargetStatuses(result_data["status"]),
491+
status=TargetStatuses(value=result_data["status"]),
492492
database_name=result_data["database_name"],
493493
target_name=result_data["target_name"],
494494
upload_date=date.fromisoformat(result_data["upload_date"]),
@@ -529,7 +529,7 @@ def get_database_summary_report(self) -> DatabaseSummaryReport:
529529
expected_result_code="Success",
530530
)
531531

532-
response_data = dict(json.loads(response.text))
532+
response_data = dict(json.loads(s=response.text))
533533
return DatabaseSummaryReport(
534534
active_images=response_data["active_images"],
535535
current_month_recos=response_data["current_month_recos"],
@@ -682,7 +682,9 @@ def update_target(
682682

683683
if image is not None:
684684
image_data = _get_image_data(image=image)
685-
image_data_encoded = base64.b64encode(image_data).decode("ascii")
685+
image_data_encoded = base64.b64encode(s=image_data).decode(
686+
encoding="ascii",
687+
)
686688
data["image"] = image_data_encoded
687689

688690
if active_flag is not None:

tests/test_vws.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def test_add_target(
4848
if application_metadata is None:
4949
encoded_metadata = None
5050
else:
51-
encoded_metadata_bytes = base64.b64encode(application_metadata)
52-
encoded_metadata = encoded_metadata_bytes.decode("utf-8")
51+
encoded_metadata_bytes = base64.b64encode(s=application_metadata)
52+
encoded_metadata = encoded_metadata_bytes.decode(encoding="utf-8")
5353

5454
target_id = vws_client.add_target(
5555
name=name,
@@ -197,7 +197,7 @@ def test_get_target_summary_report(
197197
"""
198198
date = "2018-04-25"
199199
target_name = uuid.uuid4().hex
200-
with freeze_time(date):
200+
with freeze_time(time_to_freeze=date):
201201
target_id = vws_client.add_target(
202202
name=target_name,
203203
width=1,
@@ -521,7 +521,9 @@ def test_update_target(
521521

522522
new_name = uuid.uuid4().hex
523523
new_width = secrets.choice(seq=range(1, 5000)) / 100
524-
new_application_metadata = base64.b64encode(b"a").decode("ascii")
524+
new_application_metadata = base64.b64encode(s=b"a").decode(
525+
encoding="ascii",
526+
)
525527
vws_client.update_target(
526528
target_id=target_id,
527529
name=new_name,

tests/test_vws_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_bad_image(vws_client: VWS) -> None:
121121
"""
122122
A ``BadImage`` exception is raised when a non-image is given.
123123
"""
124-
not_an_image = io.BytesIO(b"Not an image")
124+
not_an_image = io.BytesIO(initial_bytes=b"Not an image")
125125
with pytest.raises(BadImageError) as exc:
126126
vws_client.add_target(
127127
name="x",

0 commit comments

Comments
 (0)