Skip to content

Commit 510ac71

Browse files
committed
Add mypy and typing
1 parent b6a3bd3 commit 510ac71

File tree

6 files changed

+83
-16
lines changed

6 files changed

+83
-16
lines changed

blocket_api/blocket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class APIError(Exception): ...
7676
class LimitError(Exception): ...
7777

7878

79-
def _make_request(*, url, token: str, raise_for_status: bool = True) -> Response:
79+
def _make_request(*, url: str, token: str, raise_for_status: bool = True) -> Response:
8080
try:
8181
response = httpx.get(
8282
url,
@@ -170,7 +170,7 @@ def motor_search(
170170
modelYear: Optional[Tuple[int, int]] = None,
171171
milage: Optional[Tuple[int, int]] = None,
172172
gearbox: Optional[GEARBOX_OPTIONS] = None,
173-
):
173+
) -> dict:
174174
"""
175175
Search specifically in the car section of Blocket
176176
with set optional parameters for filtering.

poetry.lock

Lines changed: 65 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pre-commit = "^3.7.1"
1212
ruff = "^0.5.2"
1313
pytest = "^8.2.2"
1414
respx = "^0.21.1"
15+
mypy = "^1.15.0"
1516

1617
[project.urls]
1718
Homepage = "https://github.com/dunderrrrrr/blocket_api"

tests/assertions.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44
api = BlocketAPI("token")
55

66

7-
def test_limit_errors():
7+
def test_limit_errors() -> None:
88
with pytest.raises(LimitError):
99
api.get_listings(limit=100)
1010

1111
with pytest.raises(LimitError):
1212
api.custom_search("saab", limit=100)
1313

1414

15-
def test_typeerrors():
15+
def test_typeerrors() -> None:
1616
with pytest.raises(TypeError):
17-
api.custom_search() # missing search query
17+
# missing search query
18+
api.custom_search() # type: ignore[call-arg]
1819

1920
with pytest.raises(TypeError):
20-
BlocketAPI()
21+
# missing token
22+
BlocketAPI() # type: ignore[call-arg]

tests/requests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
api = BlocketAPI("token")
77

88

9-
def test_make_request_no_raise():
9+
def test_make_request_no_raise() -> None:
1010
_make_request(url=f"{BASE_URL}/not_found", token="token", raise_for_status=False)
1111

1212

1313
@respx.mock
14-
def test_make_request_raise_404():
14+
def test_make_request_raise_404() -> None:
1515
respx.get(f"{BASE_URL}/not_found").mock(
1616
return_value=Response(status_code=404),
1717
)
@@ -20,7 +20,7 @@ def test_make_request_raise_404():
2020

2121

2222
@respx.mock
23-
def test_make_request_raise_401():
23+
def test_make_request_raise_401() -> None:
2424
respx.get(f"{BASE_URL}/unauthorized").mock(
2525
return_value=Response(status_code=401),
2626
)

tests/searches.py

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

77

88
@respx.mock
9-
def test_saved_searches():
9+
def test_saved_searches() -> None:
1010
"""
1111
Make sure mobility saved searches are merged with v2/searches.
1212
"""
@@ -35,15 +35,15 @@ def test_saved_searches():
3535

3636

3737
@respx.mock
38-
def test_for_search_id():
38+
def test_for_search_id() -> None:
3939
respx.get(f"{BASE_URL}/saved/v2/searches_content/123?lim=99").mock(
4040
return_value=Response(status_code=200, json={"data": "listings-data"}),
4141
)
4242
assert api.get_listings(search_id=123) == {"data": "listings-data"}
4343

4444

4545
@respx.mock
46-
def test_for_search_id_mobility():
46+
def test_for_search_id_mobility() -> None:
4747
respx.get(f"{BASE_URL}/saved/v2/searches_content/123?lim=99").mock(
4848
return_value=Response(status_code=404),
4949
)
@@ -54,7 +54,7 @@ def test_for_search_id_mobility():
5454

5555

5656
@respx.mock
57-
def test_custom_search():
57+
def test_custom_search() -> None:
5858
respx.get(
5959
f"{BASE_URL}/search_bff/v2/content?lim=99&q=saab&r=20&status=active"
6060
).mock(
@@ -67,7 +67,7 @@ def test_custom_search():
6767

6868
class Test_MotorSearchURLs:
6969
@respx.mock
70-
def test_make_filter(self):
70+
def test_make_filter(self) -> None:
7171
expected_url_filter = '?filter={"key": "make", "values": ["Audi", "Toyota"]}'
7272
respx.get(
7373
f"{BASE_URL}/motor-search-service/v4/search/car"
@@ -79,7 +79,7 @@ def test_make_filter(self):
7979
assert api.motor_search(page=1, make=["Audi", "Toyota"]) == {"data": "ok"}
8080

8181
@respx.mock
82-
def test_range_filters(self):
82+
def test_range_filters(self) -> None:
8383
expected_url_filter = (
8484
'?filter={"key": "make", "values": ["Ford"]}'
8585
'&filter={"key": "price", "range": {"start": "1000", "end": "2000"}}'

0 commit comments

Comments
 (0)