Skip to content

Commit f26d7ee

Browse files
committed
Progress towards using beartype everywhere
1 parent 4dc01ed commit f26d7ee

25 files changed

+102
-80
lines changed

src/mock_vws/_database_matchers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def get_database_matching_client_keys(
5959
@beartype
6060
def get_database_matching_server_keys(
6161
*,
62-
request_headers: dict[str, str],
62+
request_headers: Mapping[str, str],
6363
request_body: bytes | None,
6464
request_method: str,
6565
request_path: str,

src/mock_vws/_flask_server/vws.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import uuid
1313
from enum import StrEnum, auto
1414
from http import HTTPMethod, HTTPStatus
15+
from typing import SupportsFloat
1516

1617
import requests
1718
from beartype import beartype
@@ -67,7 +68,7 @@ class VWSSettings(BaseSettings):
6768
"""Settings for the VWS Flask app."""
6869

6970
target_manager_base_url: str
70-
processing_time_seconds: float = 2
71+
processing_time_seconds: SupportsFloat = 2
7172
vws_host: str = ""
7273
duplicates_image_matcher: _ImageMatcherChoice = (
7374
_ImageMatcherChoice.STRUCTURAL_SIMILARITY

src/mock_vws/_query_validators/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from typing import TYPE_CHECKING
88

9+
from beartype import beartype
10+
911
from .accept_header_validators import validate_accept_header
1012
from .auth_validators import (
1113
validate_auth_header_exists,
@@ -38,13 +40,16 @@
3840
from .project_state_validators import validate_project_state
3941

4042
if TYPE_CHECKING:
43+
from collections.abc import Mapping
44+
4145
from mock_vws.database import VuforiaDatabase
4246

4347

48+
@beartype
4449
def run_query_validators(
4550
*,
4651
request_path: str,
47-
request_headers: dict[str, str],
52+
request_headers: Mapping[str, str],
4853
request_body: bytes,
4954
request_method: str,
5055
databases: set[VuforiaDatabase],

src/mock_vws/_query_validators/accept_header_validators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import logging
6+
from collections.abc import Mapping
67

78
from beartype import beartype
89

@@ -12,7 +13,7 @@
1213

1314

1415
@beartype
15-
def validate_accept_header(request_headers: dict[str, str]) -> None:
16+
def validate_accept_header(request_headers: Mapping[str, str]) -> None:
1617
"""
1718
Validate the accept header.
1819

src/mock_vws/_query_validators/content_length_validators.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import logging
6+
from collections.abc import Mapping
67

78
from beartype import beartype
89

@@ -18,7 +19,7 @@
1819
@beartype
1920
def validate_content_length_header_is_int(
2021
*,
21-
request_headers: dict[str, str],
22+
request_headers: Mapping[str, str],
2223
) -> None:
2324
"""
2425
Validate the ``Content-Length`` header is an integer.
@@ -42,7 +43,7 @@ def validate_content_length_header_is_int(
4243
@beartype
4344
def validate_content_length_header_not_too_large(
4445
*,
45-
request_headers: dict[str, str],
46+
request_headers: Mapping[str, str],
4647
request_body: bytes,
4748
) -> None:
4849
"""
@@ -69,7 +70,7 @@ def validate_content_length_header_not_too_large(
6970
@beartype
7071
def validate_content_length_header_not_too_small(
7172
*,
72-
request_headers: dict[str, str],
73+
request_headers: Mapping[str, str],
7374
request_body: bytes,
7475
) -> None:
7576
"""

src/mock_vws/_query_validators/content_type_validators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import logging
6+
from collections.abc import Mapping
67
from email.message import EmailMessage
78

89
from beartype import beartype
@@ -19,7 +20,7 @@
1920

2021
@beartype
2122
def validate_content_type_header(
22-
request_headers: dict[str, str],
23+
request_headers: Mapping[str, str],
2324
request_body: bytes,
2425
) -> None:
2526
"""

src/mock_vws/_query_validators/date_validators.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import contextlib
66
import datetime
77
import logging
8+
from collections.abc import Mapping
89
from zoneinfo import ZoneInfo
910

1011
from beartype import beartype
@@ -19,7 +20,7 @@
1920

2021

2122
@beartype
22-
def validate_date_header_given(*, request_headers: dict[str, str]) -> None:
23+
def validate_date_header_given(*, request_headers: Mapping[str, str]) -> None:
2324
"""
2425
Validate the date header is given to the query endpoint.
2526
@@ -56,7 +57,7 @@ def _accepted_date_formats() -> set[str]:
5657

5758

5859
@beartype
59-
def validate_date_format(*, request_headers: dict[str, str]) -> None:
60+
def validate_date_format(*, request_headers: Mapping[str, str]) -> None:
6061
"""
6162
Validate the format of the date header given to the query endpoint.
6263
@@ -78,7 +79,7 @@ def validate_date_format(*, request_headers: dict[str, str]) -> None:
7879

7980

8081
@beartype
81-
def validate_date_in_range(*, request_headers: dict[str, str]) -> None:
82+
def validate_date_in_range(*, request_headers: Mapping[str, str]) -> None:
8283
"""
8384
Validate date in the date header given to the query endpoint.
8485

src/mock_vws/_query_validators/fields_validators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import io
66
import logging
7+
from collections.abc import Mapping
78
from email.message import EmailMessage
89

910
from beartype import beartype
@@ -17,7 +18,7 @@
1718
@beartype
1819
def validate_extra_fields(
1920
*,
20-
request_headers: dict[str, str],
21+
request_headers: Mapping[str, str],
2122
request_body: bytes,
2223
) -> None:
2324
"""

src/mock_vws/_query_validators/image_validators.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import io
66
import logging
7+
from collections.abc import Mapping
78
from email.message import EmailMessage
89

910
from beartype import beartype
@@ -22,7 +23,7 @@
2223
@beartype
2324
def validate_image_field_given(
2425
*,
25-
request_headers: dict[str, str],
26+
request_headers: Mapping[str, str],
2627
request_body: bytes,
2728
) -> None:
2829
"""
@@ -54,7 +55,7 @@ def validate_image_field_given(
5455
@beartype
5556
def validate_image_file_size(
5657
*,
57-
request_headers: dict[str, str],
58+
request_headers: Mapping[str, str],
5859
request_body: bytes,
5960
) -> None:
6061
"""
@@ -95,7 +96,7 @@ def validate_image_file_size(
9596
@beartype
9697
def validate_image_dimensions(
9798
*,
98-
request_headers: dict[str, str],
99+
request_headers: Mapping[str, str],
99100
request_body: bytes,
100101
) -> None:
101102
"""
@@ -134,7 +135,7 @@ def validate_image_dimensions(
134135
@beartype
135136
def validate_image_format(
136137
*,
137-
request_headers: dict[str, str],
138+
request_headers: Mapping[str, str],
138139
request_body: bytes,
139140
) -> None:
140141
"""
@@ -168,7 +169,7 @@ def validate_image_format(
168169

169170
@beartype
170171
def validate_image_is_image(
171-
request_headers: dict[str, str],
172+
request_headers: Mapping[str, str],
172173
request_body: bytes,
173174
) -> None:
174175
"""

src/mock_vws/_query_validators/include_target_data_validators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import io
66
import logging
7+
from collections.abc import Mapping
78
from email.message import EmailMessage
89

910
from beartype import beartype
@@ -16,7 +17,7 @@
1617

1718
@beartype
1819
def validate_include_target_data(
19-
request_headers: dict[str, str],
20+
request_headers: Mapping[str, str],
2021
request_body: bytes,
2122
) -> None:
2223
"""

0 commit comments

Comments
 (0)