Skip to content

Commit 6816e60

Browse files
committed
Use new Python typing style
1 parent e784607 commit 6816e60

File tree

14 files changed

+56
-48
lines changed

14 files changed

+56
-48
lines changed

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
Setup script for VWS Python Mock, a mock of Vuforia's Web Services APIs.
33
"""
44

5+
from __future__ import annotations
6+
57
from pathlib import Path
6-
from typing import List
78

89
from setuptools import setup
910

1011

11-
def _get_dependencies(requirements_file: Path) -> List[str]:
12+
def _get_dependencies(requirements_file: Path) -> list[str]:
1213
"""
1314
Return requirements from a requirements file.
1415

src/mock_vws/_database_matchers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
Helpers for getting databases which match keys given in requests.
33
"""
44

5-
from typing import Dict, Iterable, Optional
5+
from __future__ import annotations
6+
7+
from typing import Dict, Iterable
68

79
from vws_auth_tools import authorization_header
810

@@ -11,11 +13,11 @@
1113

1214
def get_database_matching_client_keys(
1315
request_headers: Dict[str, str],
14-
request_body: Optional[bytes],
16+
request_body: bytes | None,
1517
request_method: str,
1618
request_path: str,
1719
databases: Iterable[VuforiaDatabase],
18-
) -> Optional[VuforiaDatabase]:
20+
) -> VuforiaDatabase | None:
1921
"""
2022
Return which, if any, of the given databases is being accessed by the given
2123
client request.
@@ -53,11 +55,11 @@ def get_database_matching_client_keys(
5355

5456
def get_database_matching_server_keys(
5557
request_headers: Dict[str, str],
56-
request_body: Optional[bytes],
58+
request_body: bytes | None,
5759
request_method: str,
5860
request_path: str,
5961
databases: Iterable[VuforiaDatabase],
60-
) -> Optional[VuforiaDatabase]:
62+
) -> VuforiaDatabase | None:
6163
"""
6264
Return which, if any, of the given databases is being accessed by the given
6365
server request.

src/mock_vws/_flask_server/vwq.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class ResponseNoContentTypeAdded(Response):
6969
Without this, a content type is added to all responses.
7070
Some of our responses need to not have a "Content-Type" header.
7171
"""
72+
7273
default_mimetype = None
7374

7475

src/mock_vws/_flask_server/vws.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import os
1212
import uuid
1313
from http import HTTPStatus
14-
from typing import List, Set
14+
from typing import Set
1515

1616
import requests
1717
from flask import Flask, Response, request
@@ -52,6 +52,7 @@ class ResponseNoContentTypeAdded(Response):
5252
Without this, a content type is added to all responses.
5353
Some of our responses need to not have a "Content-Type" header.
5454
"""
55+
5556
default_mimetype = None
5657

5758

@@ -394,7 +395,7 @@ def get_duplicates(target_id: str) -> Response:
394395
]
395396
other_targets = set(database.targets) - {target}
396397

397-
similar_targets: List[str] = [
398+
similar_targets: list[str] = [
398399
other.target_id
399400
for other in other_targets
400401
if other.image_value == target.image_value

src/mock_vws/_query_tools.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import datetime
88
import io
99
import uuid
10-
from typing import Any, Dict, List, Set, Union
10+
from typing import Any, Dict, Set
1111

1212
from backports.zoneinfo import ZoneInfo
1313

@@ -30,8 +30,8 @@ def get_query_match_response_text(
3030
request_method: str,
3131
request_path: str,
3232
databases: Set[VuforiaDatabase],
33-
query_processes_deletion_seconds: Union[int, float],
34-
query_recognizes_deletion_seconds: Union[int, float],
33+
query_processes_deletion_seconds: int | float,
34+
query_recognizes_deletion_seconds: int | float,
3535
) -> str:
3636
"""
3737
Args:
@@ -129,7 +129,7 @@ def get_query_match_response_text(
129129

130130
matches = not_deleted_matches + deletion_not_recognized_matches
131131

132-
results: List[Dict[str, Any]] = []
132+
results: list[Dict[str, Any]] = []
133133
for target in matches:
134134
target_timestamp = target.last_modified_date.timestamp()
135135
if target.application_metadata is None:

src/mock_vws/_requests_mock_server/decorators.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
Decorators for using the mock.
33
"""
44

5+
from __future__ import annotations
6+
57
import re
68
from contextlib import ContextDecorator
7-
from typing import Literal, Tuple, Union
9+
from typing import Literal, Tuple
810
from urllib.parse import urljoin, urlparse
911

1012
import requests
@@ -27,9 +29,9 @@ def __init__(
2729
base_vws_url: str = 'https://vws.vuforia.com',
2830
base_vwq_url: str = 'https://cloudreco.vuforia.com',
2931
real_http: bool = False,
30-
processing_time_seconds: Union[int, float] = 0.5,
31-
query_recognizes_deletion_seconds: Union[int, float] = 0.2,
32-
query_processes_deletion_seconds: Union[int, float] = 3,
32+
processing_time_seconds: int | float = 0.5,
33+
query_recognizes_deletion_seconds: int | float = 0.2,
34+
query_processes_deletion_seconds: int | float = 3,
3335
) -> None:
3436
"""
3537
Route requests to Vuforia's Web Service APIs to fakes of those APIs.

src/mock_vws/_requests_mock_server/mock_web_query_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
import email.utils
9-
from typing import Callable, Set, Union
9+
from typing import Callable, Set
1010

1111
from requests_mock import POST
1212
from requests_mock.request import _RequestObjectProxy
@@ -74,8 +74,8 @@ class MockVuforiaWebQueryAPI:
7474
def __init__(
7575
self,
7676
target_manager: TargetManager,
77-
query_recognizes_deletion_seconds: Union[int, float],
78-
query_processes_deletion_seconds: Union[int, float],
77+
query_recognizes_deletion_seconds: int | float,
78+
query_processes_deletion_seconds: int | float,
7979
) -> None:
8080
"""
8181
Args:

src/mock_vws/_requests_mock_server/mock_web_services_api.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API
66
"""
77

8+
from __future__ import annotations
9+
810
import base64
911
import dataclasses
1012
import datetime
1113
import email.utils
1214
import random
1315
import uuid
1416
from http import HTTPStatus
15-
from typing import Callable, Dict, List, Set, Union
17+
from typing import Callable, Dict, Set
1618

1719
from backports.zoneinfo import ZoneInfo
1820
from requests_mock import DELETE, GET, POST, PUT
@@ -86,7 +88,7 @@ class MockVuforiaWebServicesAPI:
8688
def __init__(
8789
self,
8890
target_manager: TargetManager,
89-
processing_time_seconds: Union[int, float],
91+
processing_time_seconds: int | float,
9092
) -> None:
9193
"""
9294
Args:
@@ -268,7 +270,7 @@ def database_summary(
268270
context.status_code = exc.status_code
269271
return exc.response_text
270272

271-
body: Dict[str, Union[str, int]] = {}
273+
body: Dict[str, str | int] = {}
272274

273275
database = get_database_matching_server_keys(
274276
request_headers=request.headers,
@@ -343,7 +345,7 @@ def target_list(
343345
date = email.utils.formatdate(None, localtime=False, usegmt=True)
344346

345347
results = [target.target_id for target in database.not_deleted_targets]
346-
body: Dict[str, Union[str, List[str]]] = {
348+
body: Dict[str, str | list[str]] = {
347349
'transaction_id': uuid.uuid4().hex,
348350
'result_code': ResultCodes.SUCCESS.value,
349351
'results': results,
@@ -461,7 +463,7 @@ def get_duplicates(
461463

462464
other_targets = set(database.targets) - {target}
463465

464-
similar_targets: List[str] = [
466+
similar_targets: list[str] = [
465467
other.target_id
466468
for other in other_targets
467469
if other.image_value == target.image_value

src/mock_vws/database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import uuid
88
from dataclasses import dataclass, field
9-
from typing import List, Set, TypedDict
9+
from typing import Set, TypedDict
1010

1111
from mock_vws._constants import TargetStatuses
1212
from mock_vws.states import States
@@ -24,7 +24,7 @@ class DatabaseDict(TypedDict):
2424
client_access_key: str
2525
client_secret_key: str
2626
state_name: str
27-
targets: List[TargetDict]
27+
targets: list[TargetDict]
2828

2929

3030
def _random_hex() -> str:

src/mock_vws/target.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import statistics
1111
import uuid
1212
from dataclasses import dataclass, field
13-
from typing import Optional, TypedDict, Union
13+
from typing import TypedDict
1414

1515
from backports.zoneinfo import ZoneInfo
1616
from PIL import Image, ImageStat
@@ -27,12 +27,12 @@ class TargetDict(TypedDict):
2727
width: float
2828
image_base64: str
2929
active_flag: bool
30-
processing_time_seconds: Union[int, float]
30+
processing_time_seconds: int | float
3131
processed_tracking_rating: int
32-
application_metadata: Optional[str]
32+
application_metadata: str | None
3333
target_id: str
3434
last_modified_date: str
35-
delete_date_optional: Optional[str]
35+
delete_date_optional: str | None
3636
upload_date: str
3737

3838

@@ -66,13 +66,13 @@ class Target:
6666
"""
6767

6868
active_flag: bool
69-
application_metadata: Optional[str]
69+
application_metadata: str | None
7070
image_value: bytes
7171
name: str
7272
processing_time_seconds: float
7373
width: float
7474
current_month_recos: int = 0
75-
delete_date: Optional[datetime.datetime] = None
75+
delete_date: datetime.datetime | None = None
7676
last_modified_date: datetime.datetime = field(default_factory=_time_now)
7777
previous_month_recos: int = 0
7878
processed_tracking_rating: int = field(
@@ -208,7 +208,7 @@ def to_dict(self) -> TargetDict:
208208
"""
209209
Dump a target to a dictionary which can be loaded as JSON.
210210
"""
211-
delete_date: Optional[str] = None
211+
delete_date: str | None = None
212212
if self.delete_date:
213213
delete_date = datetime.datetime.isoformat(self.delete_date)
214214

0 commit comments

Comments
 (0)