fix(redis): make xadd fields use SupportsItems (#10780)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
Mehdi ABAAKOUK
2024-02-17 17:48:01 +01:00
committed by GitHub
parent 955cdf50d5
commit 522f4bc9bf
2 changed files with 21 additions and 3 deletions

View File

@@ -0,0 +1,16 @@
from typing import TypedDict
import redis
class RedisStreamData(TypedDict):
foo: str
bar: bytes
def check_xadd(r: redis.Redis[str]) -> None:
# check that TypedDicts are accepted for the `fields` parameter of `xadd()`
#
# N.B. the `pyright: ignore` is not part of the test,
# it's just because the return type is currently unannotated
r.xadd("stream", fields=RedisStreamData({"foo": "bar", "bar": b"foo"})) # pyright: ignore[reportUnknownMemberType]

View File

@@ -1,5 +1,5 @@
import builtins
from _typeshed import Incomplete
from _typeshed import Incomplete, SupportsItems
from collections.abc import AsyncIterator, Awaitable, Callable, Iterable, Iterator, Mapping, Sequence
from datetime import datetime, timedelta
from typing import Any, Generic, Literal, TypeVar, overload
@@ -862,7 +862,8 @@ class StreamCommands:
def xadd(
self,
name: KeyT,
fields: Mapping[bytes | memoryview | str | float, bytes | memoryview | str | float],
# Only accepts dict objects, but for variance reasons we use a looser annotation
fields: SupportsItems[bytes | memoryview | str | float, Any],
id: str | int | bytes | memoryview = "*",
maxlen=None,
approximate: bool = True,
@@ -928,7 +929,8 @@ class AsyncStreamCommands:
async def xadd(
self,
name: KeyT,
fields: Mapping[bytes | memoryview | str | float, bytes | memoryview | str | float],
# Only accepts dict objects, but for variance reasons we use a looser annotation
fields: SupportsItems[bytes | memoryview | str | float, Any],
id: str | int | bytes | memoryview = "*",
maxlen=None,
approximate: bool = True,