Skip to content

Commit fff6338

Browse files
committed
fix type hint asynciteration deprecation
1 parent c006407 commit fff6338

7 files changed

Lines changed: 15 additions & 15 deletions

File tree

Chapter03/reservation-service/presentation/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
import time
3-
from collections.abc import AsyncIterator, Awaitable, Callable
3+
from collections.abc import AsyncGenerator, Awaitable, Callable
44
from contextlib import asynccontextmanager
55
from typing import TypedDict
66

@@ -22,7 +22,7 @@ class State(TypedDict):
2222

2323

2424
@asynccontextmanager
25-
async def lifespan(_app: FastAPI) -> AsyncIterator[State]:
25+
async def lifespan(_app: FastAPI) -> AsyncGenerator[State]:
2626
"""
2727
Lifespan context manager for application startup and shutdown.
2828
Initializes the repository and stores it in application state.

Chapter05/api-gateway/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections.abc import AsyncIterator
1+
from collections.abc import AsyncGenerator
22
from contextlib import asynccontextmanager
33
from typing import TypedDict
44

@@ -30,7 +30,7 @@ class State(TypedDict):
3030

3131

3232
@asynccontextmanager
33-
async def lifespan(_app: FastAPI) -> AsyncIterator[State]:
33+
async def lifespan(_app: FastAPI) -> AsyncGenerator[State]:
3434
# Startup: Initialize service clients from container
3535
portal_client = container.portal_client()
3636
reservation_client = container.reservation_client()

Chapter05/api-gateway/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def app_with_limiter(limiter):
4848

4949
@app.exception_handler(RateLimitExceeded)
5050
async def rate_limit_handler(
51-
_request: Request, exc: RateLimitExceeded
51+
_request: Request, _exc: RateLimitExceeded
5252
):
5353
from fastapi.responses import JSONResponse
5454

@@ -67,7 +67,7 @@ async def rate_limit_handler(
6767

6868
@app.get("/test")
6969
@limiter.limit("2/minute")
70-
async def test_endpoint(request: Request, response: Response):
70+
async def test_endpoint(request: Request, _response: Response):
7171
del request
7272
return {"message": "ok"}
7373

Chapter05/api-gateway/tests/test_aggregation_router.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections.abc import AsyncIterator
1+
from collections.abc import AsyncGenerator
22
from contextlib import asynccontextmanager
33
from uuid import uuid4
44

@@ -79,7 +79,7 @@ def client(mock_portal_client, populated_reservation_client):
7979
"""Create test client with mock clients using lifespan."""
8080

8181
@asynccontextmanager
82-
async def test_lifespan(app: FastAPI) -> AsyncIterator[dict]:
82+
async def test_lifespan(_app: FastAPI) -> AsyncGenerator[dict]:
8383
yield {
8484
"portal_client": mock_portal_client,
8585
"reservation_client": populated_reservation_client,

Chapter05/api-gateway/tests/test_app_integration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections.abc import AsyncIterator
1+
from collections.abc import AsyncGenerator
22
from contextlib import asynccontextmanager
33
from uuid import uuid4
44

@@ -54,7 +54,7 @@ def app_with_rate_limiter(
5454
"""Create app with mock clients and rate limiter."""
5555

5656
@asynccontextmanager
57-
async def test_lifespan(app: FastAPI) -> AsyncIterator[dict]:
57+
async def test_lifespan(_app: FastAPI) -> AsyncGenerator[dict]:
5858
yield {
5959
"portal_client": mock_portal_client,
6060
"reservation_client": populated_reservation_client,
@@ -105,7 +105,7 @@ async def availability_summary(
105105

106106
@app.get("/aggregate/health")
107107
@limiter.limit("5/minute")
108-
async def health(request: Request, response: Response):
108+
async def health(request: Request, _response: Response):
109109
del request
110110
from routers.aggregation import fetch_aggregated_health
111111

Chapter07/sitters-catalog/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Shared test fixtures used across all test modules.
33
"""
44

5-
from collections.abc import AsyncIterator, Iterator
5+
from collections.abc import AsyncGenerator, Iterator
66
from contextlib import asynccontextmanager
77
from datetime import UTC, datetime
88
from unittest.mock import MagicMock
@@ -122,7 +122,7 @@ def app(repository: TinyDBRepository) -> FastAPI:
122122
"""Create test FastAPI app with TinyDB repository."""
123123

124124
@asynccontextmanager
125-
async def lifespan(_app: FastAPI) -> AsyncIterator[dict]:
125+
async def lifespan(_app: FastAPI) -> AsyncGenerator[dict]:
126126
yield {"repository": repository}
127127

128128
test_app = FastAPI(lifespan=lifespan)

Chapter07/sitters-catalog/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections.abc import AsyncIterator
1+
from collections.abc import AsyncGenerator
22
from contextlib import asynccontextmanager
33
from typing import TypedDict
44

@@ -39,7 +39,7 @@ class State(TypedDict):
3939

4040

4141
@asynccontextmanager
42-
async def lifespan(_app: FastAPI) -> AsyncIterator[State]:
42+
async def lifespan(_app: FastAPI) -> AsyncGenerator[State]:
4343
if settings.repository_type == RepositoryType.MONGO:
4444
yield {
4545
"repository": MongoDBRepository(settings.mongo_uri)

0 commit comments

Comments
 (0)