Skip to content

Commit b7db676

Browse files
committed
Experiment: check with mypy.
This may be reverted at any point.
1 parent 07ae539 commit b7db676

File tree

8 files changed

+37
-12
lines changed

8 files changed

+37
-12
lines changed

noxfile.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,18 @@ def lint_pylint(session: nox.Session) -> None:
323323
clean()
324324

325325

326+
@nox.session(python=["3.13"], tags=["linters"])
327+
def lint_mypy(session: nox.Session) -> None:
328+
"""
329+
Lint code with mypy.
330+
331+
"""
332+
session.install(".", "mypy")
333+
session.run(f"python{session.python}", "-Im", "mypy", "--version")
334+
session.run(f"python{session.python}", "-Im", "mypy", "src/", "tests/")
335+
clean()
336+
337+
326338
# Packaging checks.
327339
# -----------------------------------------------------------------------------------
328340

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ classifiers = [
2424
"Programming Language :: Python :: 3.13",
2525
"Programming Language :: Python :: 3.14",
2626
"Topic :: Utilities",
27+
"Typing :: Typed",
2728
]
2829
name = "akismet"
2930
description = "A Python interface to the Akismet spam-filtering service."
@@ -81,6 +82,14 @@ ignore-init-module = true
8182
[tool.isort]
8283
profile = "black"
8384

85+
[[tool.mypy.overrides]]
86+
module = ["httpx.*"]
87+
ignore_missing_imports = true
88+
89+
[[tool.mypy.overrides]]
90+
module = ["pytest.*"]
91+
ignore_missing_imports = true
92+
8493
[tool.pdm]
8594
distribution = true
8695

src/akismet/_async_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from __future__ import annotations
99

1010
from types import TracebackType
11-
from typing import TYPE_CHECKING, Literal, Optional, Type, Union
11+
from typing import TYPE_CHECKING, Literal, Optional
1212

1313
import httpx
1414
from typing_extensions import Self, Unpack
@@ -205,7 +205,7 @@ async def __aenter__(self) -> Self:
205205
return self
206206

207207
async def __aexit__(
208-
self, exc_type: Type[BaseException], exc: BaseException, tb: TracebackType
208+
self, exc_type: type[BaseException], exc: BaseException, tb: TracebackType
209209
):
210210
"""
211211
Exit method of the async context manager.
@@ -483,7 +483,7 @@ async def key_sites(
483483
order: Optional[str] = None,
484484
limit: Optional[int] = None,
485485
offset: Optional[int] = None,
486-
) -> Union[dict, str]:
486+
) -> dict | str:
487487
"""
488488
Return Akismet API usage statistics keyed by site.
489489

src/akismet/_sync_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from __future__ import annotations
99

1010
from types import TracebackType
11-
from typing import TYPE_CHECKING, Literal, Optional, Type, Union
11+
from typing import TYPE_CHECKING, Literal, Optional
1212

1313
import httpx
1414
from typing_extensions import Self, Unpack
@@ -206,7 +206,7 @@ def __enter__(self) -> Self:
206206
return self
207207

208208
def __exit__(
209-
self, exc_type: Type[BaseException], exc: BaseException, tb: TracebackType
209+
self, exc_type: type[BaseException], exc: BaseException, tb: TracebackType
210210
):
211211
"""
212212
Exit method of the context manager.
@@ -479,7 +479,7 @@ def key_sites( # pylint: disable=too-many-positional-arguments,too-many-argumen
479479
order: Optional[str] = None,
480480
limit: Optional[int] = None,
481481
offset: Optional[int] = None,
482-
) -> Union[dict, str]:
482+
) -> dict | str:
483483
"""
484484
Return Akismet API usage statistics keyed by site.
485485

src/akismet/py.typed

Whitespace-only changes.

tests/async_client/test_api.py

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

66
import csv
7+
from typing import Any, cast
78

89
import pytest
910

@@ -169,7 +170,7 @@ async def test_key_sites_json(akismet_async_client: akismet.AsyncClient):
169170
key_sites() returns key usage information in JSON format by async default.
170171
171172
"""
172-
response_json = await akismet_async_client.key_sites()
173+
response_json = cast(dict[str, Any], await akismet_async_client.key_sites())
173174
for key in ["2022-09", "limit", "offset", "total"]:
174175
assert key in response_json
175176
sites = response_json["2022-09"]
@@ -192,7 +193,7 @@ async def test_key_sites_csv(akismet_async_client: akismet.AsyncClient):
192193
193194
"""
194195
first, *rest = (
195-
await akismet_async_client.key_sites(result_format="csv")
196+
cast(str, await akismet_async_client.key_sites(result_format="csv"))
196197
).splitlines()
197198
assert first.startswith("Active sites for")
198199
reader = csv.DictReader(rest)

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def akismet_sync_client_fixed_response(
102102
marker = request.node.get_closest_marker("akismet_fixed_response")
103103
return akismet.SyncClient(
104104
http_client=httpx.Client(
105-
transport=akismet_fixed_response_transport(**marker.kwargs)
105+
transport=akismet_fixed_response_transport(**marker.kwargs) # type: ignore
106106
)
107107
)
108108

@@ -122,7 +122,7 @@ def akismet_async_client_fixed_response(
122122
marker = request.node.get_closest_marker("akismet_fixed_response")
123123
return akismet.AsyncClient(
124124
http_client=httpx.AsyncClient(
125-
transport=akismet_fixed_response_transport(**marker.kwargs)
125+
transport=akismet_fixed_response_transport(**marker.kwargs) # type: ignore
126126
)
127127
)
128128

tests/sync_client/test_api.py

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

66
import csv
7+
from typing import Any, cast
78

89
import pytest
910

@@ -169,7 +170,7 @@ def test_key_sites_json(akismet_sync_client: akismet.SyncClient):
169170
key_sites() returns key usage information in JSON format by default.
170171
171172
"""
172-
response_json = akismet_sync_client.key_sites()
173+
response_json = cast(dict[str, Any], akismet_sync_client.key_sites())
173174
for key in ["2022-09", "limit", "offset", "total"]:
174175
assert key in response_json
175176
sites = response_json["2022-09"]
@@ -191,7 +192,9 @@ def test_key_sites_csv(akismet_sync_client: akismet.SyncClient):
191192
key_sites() returns key usage information in CSV format when requested.
192193
193194
"""
194-
first, *rest = (akismet_sync_client.key_sites(result_format="csv")).splitlines()
195+
first, *rest = (
196+
cast(str, akismet_sync_client.key_sites(result_format="csv"))
197+
).splitlines()
195198
assert first.startswith("Active sites for")
196199
reader = csv.DictReader(rest)
197200
row = next(reader)

0 commit comments

Comments
 (0)