Skip to content

Commit 95ba25e

Browse files
committed
fix: resolve mypy errors (aclose attr-defined, dynamodb return type)
1 parent 3555733 commit 95ba25e

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

fastapi_cache/backends/dynamodb.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ async def init(self) -> None:
4646
).__aenter__()
4747

4848
async def close(self) -> None:
49-
self.client = await self.client.__aexit__(None, None, None)
49+
self.client = await self.client.__aexit__(None, None, None) # type: ignore[assignment,func-returns-value]
5050

5151
async def get_with_ttl(self, key: str) -> tuple[int, bytes | None]:
52-
response = await self.client.get_item(TableName=self.table_name, Key={"key": {"S": key}})
52+
response = await self.client.get_item(
53+
TableName=self.table_name, Key={"key": {"S": key}}
54+
)
5355

5456
if "Item" in response:
5557
value = response["Item"].get("value", {}).get("B")
@@ -66,19 +68,24 @@ async def get_with_ttl(self, key: str) -> tuple[int, bytes | None]:
6668
return 0, None
6769

6870
async def get(self, key: str) -> bytes | None:
69-
response = await self.client.get_item(TableName=self.table_name, Key={"key": {"S": key}})
71+
response = await self.client.get_item(
72+
TableName=self.table_name, Key={"key": {"S": key}}
73+
)
7074
if "Item" in response:
7175
return response["Item"].get("value", {}).get("B")
7276
return None
7377

74-
async def set(self, key: str, value: bytes, expire: int | None = None) -> None:
78+
async def set(
79+
self, key: str, value: bytes, expire: int | None = None
80+
) -> None:
7581
ttl = (
7682
{
7783
"ttl": {
7884
"N": str(
7985
int(
8086
(
81-
datetime.datetime.now() + datetime.timedelta(seconds=expire)
87+
datetime.datetime.now()
88+
+ datetime.timedelta(seconds=expire)
8289
).timestamp()
8390
)
8491
)
@@ -99,5 +106,7 @@ async def set(self, key: str, value: bytes, expire: int | None = None) -> None:
99106
},
100107
)
101108

102-
async def clear(self, namespace: str | None = None, key: str | None = None) -> int:
109+
async def clear(
110+
self, namespace: str | None = None, key: str | None = None
111+
) -> int:
103112
raise NotImplementedError

tests/test_properties.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def test_redis_backend_roundtrip(key: str, value: bytes) -> None:
3333

3434
assert result == value
3535

36-
await redis.aclose()
36+
await redis.aclose() # type: ignore[attr-defined]
3737

3838

3939
# Feature: redis5-prefect-compatibility, Property 2: TTL consistency after set
@@ -59,7 +59,7 @@ async def test_ttl_consistency_after_set(
5959
assert returned_ttl <= ttl
6060
assert returned_value == value
6161

62-
await redis.aclose()
62+
await redis.aclose() # type: ignore[attr-defined]
6363

6464

6565
# Feature: redis5-prefect-compatibility, Property 4: JsonCoder datetime round-trip
@@ -155,7 +155,7 @@ async def test_clear_namespace_isolation(
155155
result = await backend.get(key)
156156
assert result == other_value, f"Expected {key} to still have its value"
157157

158-
await redis.aclose()
158+
await redis.aclose() # type: ignore[attr-defined]
159159

160160

161161
# Feature: redis5-prefect-compatibility, Property 5: Clear with no arguments is a no-op
@@ -206,4 +206,4 @@ async def test_clear_no_args_is_noop(
206206
f"Expected key '{key}' to still have value {value!r}, got {stored!r}"
207207
)
208208

209-
await redis.aclose()
209+
await redis.aclose() # type: ignore[attr-defined]

0 commit comments

Comments
 (0)