Skip to content

Commit ad70497

Browse files
fix: resolve type checking issues with Mapping refactor
- Fix BaseStore return types by converting Mapping to dict in get/ttl methods - Update LoggingWrapper internal methods to accept Mapping types - Fix test mock store to use Mapping instead of dict for protocol compatibility - Fix ManagedEntry.to_json() to convert Mapping to dict - Regenerate sync library with all fixes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: William Easton <strawgate@users.noreply.github.com>
1 parent 55adfe3 commit ad70497

File tree

7 files changed

+17
-15
lines changed

7 files changed

+17
-15
lines changed

key-value/key-value-aio/src/key_value/aio/stores/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ async def get(
134134
if managed_entry.is_expired:
135135
return None
136136

137-
return managed_entry.value
137+
return dict(managed_entry.value)
138138

139139
@override
140140
async def get_many(self, keys: list[str], *, collection: str | None = None) -> list[dict[str, Any] | None]:
141141
collection = collection or self.default_collection
142142
await self.setup_collection(collection=collection)
143143

144144
entries = await self._get_managed_entries(keys=keys, collection=collection)
145-
return [entry.value if entry and not entry.is_expired else None for entry in entries]
145+
return [dict(entry.value) if entry and not entry.is_expired else None for entry in entries]
146146

147147
@override
148148
async def ttl(self, key: str, *, collection: str | None = None) -> tuple[dict[str, Any] | None, float | None]:
@@ -154,7 +154,7 @@ async def ttl(self, key: str, *, collection: str | None = None) -> tuple[dict[st
154154
if not managed_entry or managed_entry.is_expired:
155155
return (None, None)
156156

157-
return (managed_entry.value, managed_entry.ttl)
157+
return (dict(managed_entry.value), managed_entry.ttl)
158158

159159
@override
160160
async def ttl_many(
@@ -172,7 +172,7 @@ async def ttl_many(
172172
await self.setup_collection(collection=collection)
173173

174174
entries = await self._get_managed_entries(keys=keys, collection=collection)
175-
return [(entry.value, entry.ttl) if entry and not entry.is_expired else (None, None) for entry in entries]
175+
return [(dict(entry.value), entry.ttl) if entry and not entry.is_expired else (None, None) for entry in entries]
176176

177177
@abstractmethod
178178
async def _put_managed_entry(self, *, collection: str, key: str, managed_entry: ManagedEntry) -> None:

key-value/key-value-aio/src/key_value/aio/wrappers/logging/wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _format_message(
5959
action: str,
6060
keys: list[str] | str,
6161
collection: str | None,
62-
values: dict[str, Any] | Sequence[dict[str, Any]] | None = None,
62+
values: Mapping[str, Any] | Sequence[Mapping[str, Any]] | None = None,
6363
extra: dict[str, Any] | None = None,
6464
) -> str:
6565
if self.structured_logs:
@@ -92,7 +92,7 @@ def _log(
9292
action: str,
9393
keys: list[str] | str,
9494
collection: str | None,
95-
values: dict[str, Any] | Sequence[dict[str, Any]] | None = None,
95+
values: Mapping[str, Any] | Sequence[Mapping[str, Any]] | None = None,
9696
extra: dict[str, Any] | None = None,
9797
) -> None:
9898
self.logger.log(

key-value/key-value-aio/tests/stores/wrappers/test_fallback.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections.abc import Mapping
12
from typing import Any, SupportsFloat
23

34
import pytest
@@ -15,7 +16,7 @@ async def get(self, key: str, *, collection: str | None = None) -> dict[str, Any
1516
msg = "Primary store unavailable"
1617
raise ConnectionError(msg)
1718

18-
async def put(self, key: str, value: dict[str, Any], *, collection: str | None = None, ttl: SupportsFloat | None = None): # noqa: ARG002
19+
async def put(self, key: str, value: Mapping[str, Any], *, collection: str | None = None, ttl: SupportsFloat | None = None): # noqa: ARG002
1920
msg = "Primary store unavailable"
2021
raise ConnectionError(msg)
2122

key-value/key-value-shared/src/key_value/shared/utils/managed_entry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def to_json(self, include_metadata: bool = True, include_expiration: bool = True
5454
if include_expiration and self.expires_at:
5555
data["expires_at"] = self.expires_at.isoformat()
5656
else:
57-
data = self.value
57+
data = dict(self.value)
5858

5959
return dump_to_json(obj=data)
6060

key-value/key-value-sync/src/key_value/sync/code_gen/stores/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ def get(self, key: str, *, collection: str | None = None) -> dict[str, Any] | No
132132
if managed_entry.is_expired:
133133
return None
134134

135-
return managed_entry.value
135+
return dict(managed_entry.value)
136136

137137
@override
138138
def get_many(self, keys: list[str], *, collection: str | None = None) -> list[dict[str, Any] | None]:
139139
collection = collection or self.default_collection
140140
self.setup_collection(collection=collection)
141141

142142
entries = self._get_managed_entries(keys=keys, collection=collection)
143-
return [entry.value if entry and (not entry.is_expired) else None for entry in entries]
143+
return [dict(entry.value) if entry and (not entry.is_expired) else None for entry in entries]
144144

145145
@override
146146
def ttl(self, key: str, *, collection: str | None = None) -> tuple[dict[str, Any] | None, float | None]:
@@ -152,7 +152,7 @@ def ttl(self, key: str, *, collection: str | None = None) -> tuple[dict[str, Any
152152
if not managed_entry or managed_entry.is_expired:
153153
return (None, None)
154154

155-
return (managed_entry.value, managed_entry.ttl)
155+
return (dict(managed_entry.value), managed_entry.ttl)
156156

157157
@override
158158
def ttl_many(self, keys: list[str], *, collection: str | None = None) -> list[tuple[dict[str, Any] | None, float | None]]:
@@ -165,7 +165,7 @@ def ttl_many(self, keys: list[str], *, collection: str | None = None) -> list[tu
165165
self.setup_collection(collection=collection)
166166

167167
entries = self._get_managed_entries(keys=keys, collection=collection)
168-
return [(entry.value, entry.ttl) if entry and (not entry.is_expired) else (None, None) for entry in entries]
168+
return [(dict(entry.value), entry.ttl) if entry and (not entry.is_expired) else (None, None) for entry in entries]
169169

170170
@abstractmethod
171171
def _put_managed_entry(self, *, collection: str, key: str, managed_entry: ManagedEntry) -> None:

key-value/key-value-sync/src/key_value/sync/code_gen/wrappers/logging/wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _format_message(
6262
action: str,
6363
keys: list[str] | str,
6464
collection: str | None,
65-
values: dict[str, Any] | Sequence[dict[str, Any]] | None = None,
65+
values: Mapping[str, Any] | Sequence[Mapping[str, Any]] | None = None,
6666
extra: dict[str, Any] | None = None,
6767
) -> str:
6868
if self.structured_logs:
@@ -90,7 +90,7 @@ def _log(
9090
action: str,
9191
keys: list[str] | str,
9292
collection: str | None,
93-
values: dict[str, Any] | Sequence[dict[str, Any]] | None = None,
93+
values: Mapping[str, Any] | Sequence[Mapping[str, Any]] | None = None,
9494
extra: dict[str, Any] | None = None,
9595
) -> None:
9696
self.logger.log(

key-value/key-value-sync/tests/code_gen/stores/wrappers/test_fallback.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# WARNING: this file is auto-generated by 'build_sync_library.py'
22
# from the original file 'test_fallback.py'
33
# DO NOT CHANGE! Change the original file instead.
4+
from collections.abc import Mapping
45
from typing import Any, SupportsFloat
56

67
import pytest
@@ -18,7 +19,7 @@ def get(self, key: str, *, collection: str | None = None) -> dict[str, Any] | No
1819
msg = "Primary store unavailable"
1920
raise ConnectionError(msg)
2021

21-
def put(self, key: str, value: dict[str, Any], *, collection: str | None = None, ttl: SupportsFloat | None = None): # noqa: ARG002
22+
def put(self, key: str, value: Mapping[str, Any], *, collection: str | None = None, ttl: SupportsFloat | None = None): # noqa: ARG002
2223
msg = "Primary store unavailable"
2324
raise ConnectionError(msg)
2425

0 commit comments

Comments
 (0)