Skip to content

Commit cf29df7

Browse files
committed
chore(mypy): use backward compatible List annotation
1 parent 3135117 commit cf29df7

11 files changed

+23
-22
lines changed

docs/core/event_handler/appsync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ And an example for testing asynchronous resolvers. Note that this requires the `
259259

260260
=== "assert_async_graphql_response.py"
261261

262-
```python hl_lines="27"
262+
```python hl_lines="28"
263263
--8<-- "examples/event_handler_graphql/src/assert_async_graphql_response.py"
264264
```
265265

examples/event_handler_graphql/src/assert_async_graphql_response.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
from dataclasses import dataclass
33
from pathlib import Path
4+
from typing import List
45

56
import pytest
67
from assert_async_graphql_response_module import Todo, app # instance of AppSyncResolver
@@ -24,7 +25,7 @@ async def test_async_direct_resolver(lambda_context):
2425
fake_event = json.loads(Path("assert_async_graphql_response.json").read_text())
2526

2627
# WHEN
27-
result: list[Todo] = await app(fake_event, lambda_context)
28+
result: List[Todo] = await app(fake_event, lambda_context)
2829
# alternatively, you can also run a sync test against `lambda_handler`
2930
# since `lambda_handler` awaits the coroutine to complete
3031

examples/event_handler_graphql/src/assert_async_graphql_response_module.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import asyncio
2-
from typing import TypedDict
2+
from typing import List, TypedDict
33

44
import aiohttp
55

@@ -22,10 +22,10 @@ class Todo(TypedDict, total=False):
2222

2323

2424
@app.resolver(type_name="Query", field_name="listTodos")
25-
async def list_todos() -> list[Todo]:
25+
async def list_todos() -> List[Todo]:
2626
async with aiohttp.ClientSession(trace_configs=[aiohttp_trace_config()]) as session:
2727
async with session.get("https://jsonplaceholder.typicode.com/todos") as resp:
28-
result: list[Todo] = await resp.json()
28+
result: List[Todo] = await resp.json()
2929
return result[:2] # first two results to demo assertion
3030

3131

examples/event_handler_graphql/src/assert_graphql_response_module.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TypedDict
1+
from typing import List, TypedDict
22

33
from aws_lambda_powertools import Logger, Tracer
44
from aws_lambda_powertools.event_handler import AppSyncResolver
@@ -20,7 +20,7 @@ class Location(TypedDict, total=False):
2020
@app.resolver(field_name="listLocations")
2121
@app.resolver(field_name="locations")
2222
@tracer.capture_method
23-
def get_locations(name: str, description: str = "") -> list[Location]: # match GraphQL Query arguments
23+
def get_locations(name: str, description: str = "") -> List[Location]: # match GraphQL Query arguments
2424
return [{"name": name, "description": description}]
2525

2626

examples/event_handler_graphql/src/async_resolvers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import asyncio
2-
from typing import TypedDict
2+
from typing import List, TypedDict
33

44
import aiohttp
55

@@ -22,7 +22,7 @@ class Todo(TypedDict, total=False):
2222

2323

2424
@app.resolver(type_name="Query", field_name="listTodos")
25-
async def list_todos() -> list[Todo]:
25+
async def list_todos() -> List[Todo]:
2626
async with aiohttp.ClientSession(trace_configs=[aiohttp_trace_config()]) as session:
2727
async with session.get("https://jsonplaceholder.typicode.com/todos") as resp:
2828
return await resp.json()

examples/event_handler_graphql/src/custom_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TypedDict
1+
from typing import List, TypedDict
22

33
from aws_lambda_powertools import Logger, Tracer
44
from aws_lambda_powertools.event_handler import AppSyncResolver
@@ -31,7 +31,7 @@ def api_key(self) -> str:
3131

3232

3333
@app.resolver(type_name="Query", field_name="listLocations")
34-
def list_locations(page: int = 0, size: int = 10) -> list[Location]:
34+
def list_locations(page: int = 0, size: int = 10) -> List[Location]:
3535
# additional properties/methods will now be available under current_event
3636
logger.debug(f"Request country origin: {app.current_event.country_viewer}") # type: ignore[attr-defined]
3737
return [{"id": scalar_types_utils.make_id(), "name": "Perry, James and Carroll"}]

examples/event_handler_graphql/src/getting_started_graphql_api_resolver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TypedDict
1+
from typing import List, TypedDict
22

33
import requests
44
from requests import Response
@@ -34,7 +34,7 @@ def get_todo(
3434

3535
@app.resolver(type_name="Query", field_name="listTodos")
3636
@tracer.capture_method
37-
def list_todos() -> list[Todo]:
37+
def list_todos() -> List[Todo]:
3838
todos: Response = requests.get("https://jsonplaceholder.typicode.com/todos")
3939
todos.raise_for_status()
4040

examples/event_handler_graphql/src/graphql_transformer_merchant_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TypedDict
1+
from typing import List, TypedDict
22

33
from aws_lambda_powertools import Logger, Tracer
44
from aws_lambda_powertools.event_handler import AppSyncResolver
@@ -20,7 +20,7 @@ class Location(TypedDict, total=False):
2020

2121

2222
@app.resolver(type_name="Query", field_name="listLocations")
23-
def list_locations(page: int = 0, size: int = 10) -> list[Location]:
23+
def list_locations(page: int = 0, size: int = 10) -> List[Location]:
2424
return [{"id": scalar_types_utils.make_id(), "name": "Smooth Grooves"}]
2525

2626

examples/event_handler_graphql/src/graphql_transformer_search_merchant.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TypedDict
1+
from typing import List, TypedDict
22

33
from aws_lambda_powertools import Logger, Tracer
44
from aws_lambda_powertools.event_handler import AppSyncResolver
@@ -19,8 +19,8 @@ class Merchant(TypedDict, total=False):
1919

2020

2121
@app.resolver(type_name="Query", field_name="findMerchant")
22-
def find_merchant(search: str) -> list[Merchant]:
23-
merchants: list[Merchant] = [
22+
def find_merchant(search: str) -> List[Merchant]:
23+
merchants: List[Merchant] = [
2424
{
2525
"id": scalar_types_utils.make_id(),
2626
"name": "Parry-Wood",

examples/event_handler_graphql/src/nested_mappings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TypedDict
1+
from typing import List, TypedDict
22

33
from aws_lambda_powertools import Logger, Tracer
44
from aws_lambda_powertools.event_handler import AppSyncResolver
@@ -20,7 +20,7 @@ class Location(TypedDict, total=False):
2020
@app.resolver(field_name="listLocations")
2121
@app.resolver(field_name="locations")
2222
@tracer.capture_method
23-
def get_locations(name: str, description: str = "") -> list[Location]: # match GraphQL Query arguments
23+
def get_locations(name: str, description: str = "") -> List[Location]: # match GraphQL Query arguments
2424
return [{"name": name, "description": description}]
2525

2626

examples/event_handler_graphql/src/split_operation_module.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TypedDict
1+
from typing import List, TypedDict
22

33
from aws_lambda_powertools import Logger, Tracer
44
from aws_lambda_powertools.event_handler.appsync import Router
@@ -18,5 +18,5 @@ class Location(TypedDict, total=False):
1818
@router.resolver(field_name="listLocations")
1919
@router.resolver(field_name="locations")
2020
@tracer.capture_method
21-
def get_locations(name: str, description: str = "") -> list[Location]: # match GraphQL Query arguments
21+
def get_locations(name: str, description: str = "") -> List[Location]: # match GraphQL Query arguments
2222
return [{"name": name, "description": description}]

0 commit comments

Comments
 (0)