Skip to content

Commit 2fb2305

Browse files
committed
Use ResponseType
1 parent 9a74117 commit 2fb2305

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

src/mock_vws/_requests_mock_server/mock_web_query_api.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828

2929
_ROUTES: set[Route] = set()
3030

31+
_ResponseType = str
32+
3133

3234
def route(
3335
path_pattern: str,
3436
http_methods: set[str],
35-
) -> Callable[[Callable[..., str]], Callable[..., str]]:
37+
) -> Callable[[Callable[..., _ResponseType]], Callable[..., _ResponseType]]:
3638
"""
3739
Register a decorated method so that it can be recognized as a route.
3840
@@ -45,7 +47,9 @@ def route(
4547
A decorator which takes methods and makes them recognizable as routes.
4648
"""
4749

48-
def decorator(method: Callable[..., str]) -> Callable[..., str]:
50+
def decorator(
51+
method: Callable[..., _ResponseType],
52+
) -> Callable[..., _ResponseType]:
4953
"""
5054
Register a decorated method so that it can be recognized as a route.
5155
@@ -99,7 +103,7 @@ def __init__(
99103
self._query_match_checker = query_match_checker
100104

101105
@route(path_pattern="/v1/query", http_methods={HTTPMethod.POST})
102-
def query(self, request: "Request", context: "Context") -> str:
106+
def query(self, request: "Request", context: "Context") -> _ResponseType:
103107
"""
104108
Perform an image recognition query.
105109
"""

src/mock_vws/_requests_mock_server/mock_web_services_api.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@
4040

4141
_ROUTES: set[Route] = set()
4242

43+
_ResponseType = str
44+
4345

4446
def route(
4547
path_pattern: str,
4648
http_methods: set[HTTPMethod],
47-
) -> Callable[[Callable[..., str]], Callable[..., str]]:
49+
) -> Callable[[Callable[..., str]], Callable[..., _ResponseType]]:
4850
"""
4951
Register a decorated method so that it can be recognized as a route.
5052
@@ -57,7 +59,9 @@ def route(
5759
A decorator which takes methods and makes them recognizable as routes.
5860
"""
5961

60-
def decorator(method: Callable[..., str]) -> Callable[..., str]:
62+
def decorator(
63+
method: Callable[..., _ResponseType],
64+
) -> Callable[..., _ResponseType]:
6165
"""
6266
Register a decorated method so that it can be recognized as a route.
6367
@@ -130,7 +134,9 @@ def __init__(
130134
path_pattern="/targets",
131135
http_methods={HTTPMethod.POST},
132136
)
133-
def add_target(self, request: "Request", context: "Context") -> str:
137+
def add_target(
138+
self, request: "Request", context: "Context"
139+
) -> _ResponseType:
134140
"""
135141
Add a target.
136142
@@ -207,7 +213,9 @@ def add_target(self, request: "Request", context: "Context") -> str:
207213
path_pattern=f"/targets/{_TARGET_ID_PATTERN}",
208214
http_methods={HTTPMethod.DELETE},
209215
)
210-
def delete_target(self, request: "Request", context: "Context") -> str:
216+
def delete_target(
217+
self, request: "Request", context: "Context"
218+
) -> _ResponseType:
211219
"""
212220
Delete a target.
213221
@@ -274,7 +282,9 @@ def delete_target(self, request: "Request", context: "Context") -> str:
274282
return body_json
275283

276284
@route(path_pattern="/summary", http_methods={HTTPMethod.GET})
277-
def database_summary(self, request: "Request", context: "Context") -> str:
285+
def database_summary(
286+
self, request: "Request", context: "Context"
287+
) -> _ResponseType:
278288
"""
279289
Get a database summary report.
280290
@@ -340,7 +350,9 @@ def database_summary(self, request: "Request", context: "Context") -> str:
340350
return body_json
341351

342352
@route(path_pattern="/targets", http_methods={HTTPMethod.GET})
343-
def target_list(self, request: "Request", context: "Context") -> str:
353+
def target_list(
354+
self, request: "Request", context: "Context"
355+
) -> _ResponseType:
344356
"""
345357
Get a list of all targets.
346358
@@ -400,7 +412,9 @@ def target_list(self, request: "Request", context: "Context") -> str:
400412
path_pattern=f"/targets/{_TARGET_ID_PATTERN}",
401413
http_methods={HTTPMethod.GET},
402414
)
403-
def get_target(self, request: "Request", context: "Context") -> str:
415+
def get_target(
416+
self, request: "Request", context: "Context"
417+
) -> _ResponseType:
404418
"""
405419
Get details of a target.
406420
@@ -468,7 +482,9 @@ def get_target(self, request: "Request", context: "Context") -> str:
468482
path_pattern=f"/duplicates/{_TARGET_ID_PATTERN}",
469483
http_methods={HTTPMethod.GET},
470484
)
471-
def get_duplicates(self, request: "Request", context: "Context") -> str:
485+
def get_duplicates(
486+
self, request: "Request", context: "Context"
487+
) -> _ResponseType:
472488
"""
473489
Get targets which may be considered duplicates of a given target.
474490
@@ -542,7 +558,9 @@ def get_duplicates(self, request: "Request", context: "Context") -> str:
542558
path_pattern=f"/targets/{_TARGET_ID_PATTERN}",
543559
http_methods={HTTPMethod.PUT},
544560
)
545-
def update_target(self, request: "Request", context: "Context") -> str:
561+
def update_target(
562+
self, request: "Request", context: "Context"
563+
) -> _ResponseType:
546564
"""
547565
Update a target.
548566
@@ -651,7 +669,9 @@ def update_target(self, request: "Request", context: "Context") -> str:
651669
path_pattern=f"/summary/{_TARGET_ID_PATTERN}",
652670
http_methods={HTTPMethod.GET},
653671
)
654-
def target_summary(self, request: "Request", context: "Context") -> str:
672+
def target_summary(
673+
self, request: "Request", context: "Context"
674+
) -> _ResponseType:
655675
"""
656676
Get a summary report for a target.
657677

0 commit comments

Comments
 (0)