From 4255e100502c1fd330d8221d2a5805ad9a7bc3b0 Mon Sep 17 00:00:00 2001 From: kesha1225 Date: Sat, 19 Apr 2025 04:45:49 +0300 Subject: [PATCH 1/9] fix(redis-client): change `zrange` num parameter type to `Optional[int]` --- redis/commands/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis/commands/core.py b/redis/commands/core.py index a8c327f08f..d1edd7da34 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -4458,7 +4458,7 @@ def zrange( byscore: bool = False, bylex: bool = False, offset: int = None, - num: int = None, + num: Optional[int] = None, ) -> ResponseT: """ Return a range of values from sorted set ``name`` between From 393f260cb9f9d0abb6cd3ded00ecf64943f20955 Mon Sep 17 00:00:00 2001 From: kesha1225 Date: Sat, 19 Apr 2025 05:01:04 +0300 Subject: [PATCH 2/9] add changes --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 24b52c54db..7ce774621d 100644 --- a/CHANGES +++ b/CHANGES @@ -1146,3 +1146,4 @@ incompatible in code using*SCAN commands loops such as * Implemented STRLEN * Implemented PERSIST * Implemented SETRANGE + * Changed type annotation of the `num` parameter in `zrange` from `int` to `Optional[int] \ No newline at end of file From 54f35731a9ce150bf76e3a93d8fc2a1adeb2f131 Mon Sep 17 00:00:00 2001 From: kesha1225 Date: Tue, 22 Apr 2025 23:04:36 +0300 Subject: [PATCH 3/9] fix(redis-client): normalize optional parameter annotations Replace all occurrences of Union[T, None] = None and bare T = None with Optional[T] = None in zrange, _zrange, arrtrim, and other methods so that type checkers no longer report errors. --- redis/commands/core.py | 206 ++++++++++++++++---------------- redis/commands/json/commands.py | 12 +- 2 files changed, 109 insertions(+), 109 deletions(-) diff --git a/redis/commands/core.py b/redis/commands/core.py index d1edd7da34..d250f9e43f 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -63,7 +63,7 @@ class ACLCommands(CommandsProtocol): see: https://redis.io/topics/acl """ - def acl_cat(self, category: Union[str, None] = None, **kwargs) -> ResponseT: + def acl_cat(self, category: Optional[str] = None, **kwargs) -> ResponseT: """ Returns a list of categories or commands within a category. @@ -92,7 +92,7 @@ def acl_deluser(self, *username: str, **kwargs) -> ResponseT: """ return self.execute_command("ACL DELUSER", *username, **kwargs) - def acl_genpass(self, bits: Union[int, None] = None, **kwargs) -> ResponseT: + def acl_genpass(self, bits: Optional[None] = None, **kwargs) -> ResponseT: """Generate a random password value. If ``bits`` is supplied then use this number of bits, rounded to the next multiple of 4. @@ -137,7 +137,7 @@ def acl_list(self, **kwargs) -> ResponseT: """ return self.execute_command("ACL LIST", **kwargs) - def acl_log(self, count: Union[int, None] = None, **kwargs) -> ResponseT: + def acl_log(self, count: Optional[int] = None, **kwargs) -> ResponseT: """ Get ACL logs as a list. :param int count: Get logs[0:count]. @@ -190,8 +190,8 @@ def acl_setuser( username: str, enabled: bool = False, nopass: bool = False, - passwords: Union[str, Iterable[str], None] = None, - hashed_passwords: Union[str, Iterable[str], None] = None, + passwords: Optional[str, Iterable[str]] = None, + hashed_passwords: Optional[str, Iterable[str]] = None, categories: Optional[Iterable[str]] = None, commands: Optional[Iterable[str]] = None, keys: Optional[Iterable[KeyT]] = None, @@ -450,13 +450,13 @@ def client_kill(self, address: str, **kwargs) -> ResponseT: def client_kill_filter( self, - _id: Union[str, None] = None, - _type: Union[str, None] = None, - addr: Union[str, None] = None, - skipme: Union[bool, None] = None, - laddr: Union[bool, None] = None, - user: str = None, - maxage: Union[int, None] = None, + _id: Optional[str] = None, + _type: Optional[str] = None, + addr: Optional[str] = None, + skipme: Optional[bool] = None, + laddr: Optional[bool] = None, + user: Optional[str] = None, + maxage: Optional[int] = None, **kwargs, ) -> ResponseT: """ @@ -512,7 +512,7 @@ def client_info(self, **kwargs) -> ResponseT: return self.execute_command("CLIENT INFO", **kwargs) def client_list( - self, _type: Union[str, None] = None, client_id: List[EncodableT] = [], **kwargs + self, _type: Optional[str] = None, client_id: List[EncodableT] = [], **kwargs ) -> ResponseT: """ Returns a list of currently connected clients. @@ -589,7 +589,7 @@ def client_id(self, **kwargs) -> ResponseT: def client_tracking_on( self, - clientid: Union[int, None] = None, + clientid: Optional[int] = None, prefix: Sequence[KeyT] = [], bcast: bool = False, optin: bool = False, @@ -608,7 +608,7 @@ def client_tracking_on( def client_tracking_off( self, - clientid: Union[int, None] = None, + clientid: Optional[int] = None, prefix: Sequence[KeyT] = [], bcast: bool = False, optin: bool = False, @@ -628,7 +628,7 @@ def client_tracking_off( def client_tracking( self, on: bool = True, - clientid: Union[int, None] = None, + clientid: Optional[int] = None, prefix: Sequence[KeyT] = [], bcast: bool = False, optin: bool = False, @@ -988,7 +988,7 @@ def select(self, index: int, **kwargs) -> ResponseT: return self.execute_command("SELECT", index, **kwargs) def info( - self, section: Union[str, None] = None, *args: List[str], **kwargs + self, section: Optional[srt] = None, *args: List[str], **kwargs ) -> ResponseT: """ Returns a dictionary containing information about the Redis server @@ -1070,7 +1070,7 @@ def migrate( timeout: int, copy: bool = False, replace: bool = False, - auth: Union[str, None] = None, + auth: Optional[str] = None, **kwargs, ) -> ResponseT: """ @@ -1152,7 +1152,7 @@ def memory_malloc_stats(self, **kwargs) -> ResponseT: return self.execute_command("MEMORY MALLOC-STATS", **kwargs) def memory_usage( - self, key: KeyT, samples: Union[int, None] = None, **kwargs + self, key: KeyT, samples: Optional[int] = None, **kwargs ) -> ResponseT: """ Return the total memory usage for key, its value and associated @@ -1291,7 +1291,7 @@ def shutdown( raise RedisError("SHUTDOWN seems to have failed.") def slaveof( - self, host: Union[str, None] = None, port: Union[int, None] = None, **kwargs + self, host: Optional[str] = None, port: Optional[int] = None, **kwargs ) -> ResponseT: """ Set the server to be a replicated slave of the instance identified @@ -1304,7 +1304,7 @@ def slaveof( return self.execute_command("SLAVEOF", b"NO", b"ONE", **kwargs) return self.execute_command("SLAVEOF", host, port, **kwargs) - def slowlog_get(self, num: Union[int, None] = None, **kwargs) -> ResponseT: + def slowlog_get(self, num: Optional[None] = None, **kwargs) -> ResponseT: """ Get the entries from the slowlog. If ``num`` is specified, get the most recent ``num`` items. @@ -1451,7 +1451,7 @@ def __init__( self, client: Union["redis.client.Redis", "redis.asyncio.client.Redis"], key: str, - default_overflow: Union[str, None] = None, + default_overflow: Optional[str] = None, ): self.client = client self.key = key @@ -1487,7 +1487,7 @@ def incrby( fmt: str, offset: BitfieldOffsetT, increment: int, - overflow: Union[str, None] = None, + overflow: Optional[str] = None, ): """ Increment a bitfield by a given amount. @@ -1572,8 +1572,8 @@ def append(self, key: KeyT, value: EncodableT) -> ResponseT: def bitcount( self, key: KeyT, - start: Union[int, None] = None, - end: Union[int, None] = None, + start: Optional[None] = None, + end: Optional[None] = None, mode: Optional[str] = None, ) -> ResponseT: """ @@ -1595,7 +1595,7 @@ def bitcount( def bitfield( self: Union["redis.client.Redis", "redis.asyncio.client.Redis"], key: KeyT, - default_overflow: Union[str, None] = None, + default_overflow: Optional[str] = None, ) -> BitFieldOperation: """ Return a BitFieldOperation instance to conveniently construct one or @@ -1641,8 +1641,8 @@ def bitpos( self, key: KeyT, bit: int, - start: Union[int, None] = None, - end: Union[int, None] = None, + start: Optional[None] = None, + end: Optional[None] = None, mode: Optional[str] = None, ) -> ResponseT: """ @@ -1672,7 +1672,7 @@ def copy( self, source: str, destination: str, - destination_db: Union[str, None] = None, + destination_db: Optional[str] = None, replace: bool = False, ) -> ResponseT: """ @@ -2137,7 +2137,7 @@ def pttl(self, name: KeyT) -> ResponseT: return self.execute_command("PTTL", name) def hrandfield( - self, key: str, count: int = None, withvalues: bool = False + self, key: str, count: Optional[int] = None, withvalues: bool = False ) -> ResponseT: """ Return a random field from the hash value stored at key. @@ -2191,8 +2191,8 @@ def restore( value: EncodableT, replace: bool = False, absttl: bool = False, - idletime: Union[int, None] = None, - frequency: Union[int, None] = None, + idletime: Optional[None] = None, + frequency: Optional[None] = None, ) -> ResponseT: """ Create a key using the provided serialized value, previously obtained @@ -2360,7 +2360,7 @@ def stralgo( specific_argument: Union[Literal["strings"], Literal["keys"]] = "strings", len: bool = False, idx: bool = False, - minmatchlen: Union[int, None] = None, + minmatchlen: Optional[None] = None, withmatchlen: bool = False, **kwargs, ) -> ResponseT: @@ -2960,8 +2960,8 @@ def scan( self, cursor: int = 0, match: Union[PatternT, None] = None, - count: Union[int, None] = None, - _type: Union[str, None] = None, + count: Optional[None] = None, + _type: Optional[str] = None, **kwargs, ) -> ResponseT: """ @@ -2992,8 +2992,8 @@ def scan( def scan_iter( self, match: Union[PatternT, None] = None, - count: Union[int, None] = None, - _type: Union[str, None] = None, + count: Optional[None] = None, + _type: Optional[str] = None, **kwargs, ) -> Iterator: """ @@ -3022,7 +3022,7 @@ def sscan( name: KeyT, cursor: int = 0, match: Union[PatternT, None] = None, - count: Union[int, None] = None, + count: Optional[None] = None, ) -> ResponseT: """ Incrementally return lists of elements in a set. Also return a cursor @@ -3045,7 +3045,7 @@ def sscan_iter( self, name: KeyT, match: Union[PatternT, None] = None, - count: Union[int, None] = None, + count: Optional[None] = None, ) -> Iterator: """ Make an iterator using the SSCAN command so that the client doesn't @@ -3065,7 +3065,7 @@ def hscan( name: KeyT, cursor: int = 0, match: Union[PatternT, None] = None, - count: Union[int, None] = None, + count: Optional[None] = None, no_values: Union[bool, None] = None, ) -> ResponseT: """ @@ -3093,7 +3093,7 @@ def hscan_iter( self, name: str, match: Union[PatternT, None] = None, - count: Union[int, None] = None, + count: Optional[None] = None, no_values: Union[bool, None] = None, ) -> Iterator: """ @@ -3121,7 +3121,7 @@ def zscan( name: KeyT, cursor: int = 0, match: Union[PatternT, None] = None, - count: Union[int, None] = None, + count: Optional[None] = None, score_cast_func: Union[type, Callable] = float, ) -> ResponseT: """ @@ -3148,7 +3148,7 @@ def zscan_iter( self, name: KeyT, match: Union[PatternT, None] = None, - count: Union[int, None] = None, + count: Optional[None] = None, score_cast_func: Union[type, Callable] = float, ) -> Iterator: """ @@ -3177,8 +3177,8 @@ class AsyncScanCommands(ScanCommands): async def scan_iter( self, match: Union[PatternT, None] = None, - count: Union[int, None] = None, - _type: Union[str, None] = None, + count: Optional[None] = None, + _type: Optional[str] = None, **kwargs, ) -> AsyncIterator: """ @@ -3207,7 +3207,7 @@ async def sscan_iter( self, name: KeyT, match: Union[PatternT, None] = None, - count: Union[int, None] = None, + count: Optional[None] = None, ) -> AsyncIterator: """ Make an iterator using the SSCAN command so that the client doesn't @@ -3229,7 +3229,7 @@ async def hscan_iter( self, name: str, match: Union[PatternT, None] = None, - count: Union[int, None] = None, + count: Optional[None] = None, no_values: Union[bool, None] = None, ) -> AsyncIterator: """ @@ -3258,7 +3258,7 @@ async def zscan_iter( self, name: KeyT, match: Union[PatternT, None] = None, - count: Union[int, None] = None, + count: Optional[None] = None, score_cast_func: Union[type, Callable] = float, ) -> AsyncIterator: """ @@ -3489,11 +3489,11 @@ def xadd( name: KeyT, fields: Dict[FieldT, EncodableT], id: StreamIdT = "*", - maxlen: Union[int, None] = None, + maxlen: Optional[None] = None, approximate: bool = True, nomkstream: bool = False, minid: Union[StreamIdT, None] = None, - limit: Union[int, None] = None, + limit: Optional[None] = None, ) -> ResponseT: """ Add to a stream. @@ -3544,7 +3544,7 @@ def xautoclaim( consumername: ConsumerT, min_idle_time: int, start_id: StreamIdT = "0-0", - count: Union[int, None] = None, + count: Optional[None] = None, justid: bool = False, ) -> ResponseT: """ @@ -3595,9 +3595,9 @@ def xclaim( consumername: ConsumerT, min_idle_time: int, message_ids: Union[List[StreamIdT], Tuple[StreamIdT]], - idle: Union[int, None] = None, - time: Union[int, None] = None, - retrycount: Union[int, None] = None, + idle: Optional[None] = None, + time: Optional[None] = None, + retrycount: Optional[None] = None, force: bool = False, justid: bool = False, ) -> ResponseT: @@ -3829,7 +3829,7 @@ def xpending_range( max: StreamIdT, count: int, consumername: Union[ConsumerT, None] = None, - idle: Union[int, None] = None, + idle: Optional[None] = None, ) -> ResponseT: """ Returns information about pending messages, in a range. @@ -3883,7 +3883,7 @@ def xrange( name: KeyT, min: StreamIdT = "-", max: StreamIdT = "+", - count: Union[int, None] = None, + count: Optional[None] = None, ) -> ResponseT: """ Read stream values within an interval. @@ -3913,8 +3913,8 @@ def xrange( def xread( self, streams: Dict[KeyT, StreamIdT], - count: Union[int, None] = None, - block: Union[int, None] = None, + count: Optional[None] = None, + block: Optional[None] = None, ) -> ResponseT: """ Block and monitor multiple streams for new data. @@ -3953,8 +3953,8 @@ def xreadgroup( groupname: str, consumername: str, streams: Dict[KeyT, StreamIdT], - count: Union[int, None] = None, - block: Union[int, None] = None, + count: Optional[None] = None, + block: Optional[None] = None, noack: bool = False, ) -> ResponseT: """ @@ -4000,7 +4000,7 @@ def xrevrange( name: KeyT, max: StreamIdT = "+", min: StreamIdT = "-", - count: Union[int, None] = None, + count: Optional[None] = None, ) -> ResponseT: """ Read stream values within an interval, in reverse order. @@ -4030,10 +4030,10 @@ def xrevrange( def xtrim( self, name: KeyT, - maxlen: Union[int, None] = None, + maxlen: Optional[None] = None, approximate: bool = True, minid: Union[StreamIdT, None] = None, - limit: Union[int, None] = None, + limit: Optional[None] = None, ) -> ResponseT: """ Trims old messages from a stream. @@ -4205,7 +4205,7 @@ def zincrby(self, name: KeyT, amount: float, value: EncodableT) -> ResponseT: return self.execute_command("ZINCRBY", name, amount, value) def zinter( - self, keys: KeysT, aggregate: Union[str, None] = None, withscores: bool = False + self, keys: KeysT, aggregate: Optional[str] = None, withscores: bool = False ) -> ResponseT: """ Return the intersect of multiple sorted sets specified by ``keys``. @@ -4224,7 +4224,7 @@ def zinterstore( self, dest: KeyT, keys: Union[Sequence[KeyT], Mapping[AnyKeyT, float]], - aggregate: Union[str, None] = None, + aggregate: Optional[str] = None, ) -> ResponseT: """ Intersect multiple sorted sets specified by ``keys`` into a new @@ -4263,7 +4263,7 @@ def zlexcount(self, name, min, max): """ return self.execute_command("ZLEXCOUNT", name, min, max, keys=[name]) - def zpopmax(self, name: KeyT, count: Union[int, None] = None) -> ResponseT: + def zpopmax(self, name: KeyT, count: Optional[None] = None) -> ResponseT: """ Remove and return up to ``count`` members with the highest scores from the sorted set ``name``. @@ -4274,7 +4274,7 @@ def zpopmax(self, name: KeyT, count: Union[int, None] = None) -> ResponseT: options = {"withscores": True} return self.execute_command("ZPOPMAX", name, *args, **options) - def zpopmin(self, name: KeyT, count: Union[int, None] = None) -> ResponseT: + def zpopmin(self, name: KeyT, count: Optional[None] = None) -> ResponseT: """ Remove and return up to ``count`` members with the lowest scores from the sorted set ``name``. @@ -4286,7 +4286,7 @@ def zpopmin(self, name: KeyT, count: Union[int, None] = None) -> ResponseT: return self.execute_command("ZPOPMIN", name, *args, **options) def zrandmember( - self, key: KeyT, count: int = None, withscores: bool = False + self, key: KeyT, count: Optional[int] = None, withscores: bool = False ) -> ResponseT: """ Return a random element from the sorted set value stored at key. @@ -4418,8 +4418,8 @@ def _zrange( bylex: bool = False, withscores: bool = False, score_cast_func: Union[type, Callable, None] = float, - offset: Union[int, None] = None, - num: Union[int, None] = None, + offset: Optional[None] = None, + num: Optional[None] = None, ) -> ResponseT: if byscore and bylex: raise DataError("``byscore`` and ``bylex`` can not be specified together.") @@ -4457,7 +4457,7 @@ def zrange( score_cast_func: Union[type, Callable] = float, byscore: bool = False, bylex: bool = False, - offset: int = None, + offset: Optional[int] = None, num: Optional[int] = None, ) -> ResponseT: """ @@ -4545,8 +4545,8 @@ def zrangestore( byscore: bool = False, bylex: bool = False, desc: bool = False, - offset: Union[int, None] = None, - num: Union[int, None] = None, + offset: Optional[None] = None, + num: Optional[None] = None, ) -> ResponseT: """ Stores in ``dest`` the result of a range of values from sorted set @@ -4591,8 +4591,8 @@ def zrangebylex( name: KeyT, min: EncodableT, max: EncodableT, - start: Union[int, None] = None, - num: Union[int, None] = None, + start: Optional[None] = None, + num: Optional[None] = None, ) -> ResponseT: """ Return the lexicographical range of values from sorted set ``name`` @@ -4615,8 +4615,8 @@ def zrevrangebylex( name: KeyT, max: EncodableT, min: EncodableT, - start: Union[int, None] = None, - num: Union[int, None] = None, + start: Optional[None] = None, + num: Optional[None] = None, ) -> ResponseT: """ Return the reversed lexicographical range of values from sorted set @@ -4639,8 +4639,8 @@ def zrangebyscore( name: KeyT, min: ZScoreBoundT, max: ZScoreBoundT, - start: Union[int, None] = None, - num: Union[int, None] = None, + start: Optional[None] = None, + num: Optional[None] = None, withscores: bool = False, score_cast_func: Union[type, Callable] = float, ) -> ResponseT: @@ -4674,8 +4674,8 @@ def zrevrangebyscore( name: KeyT, max: ZScoreBoundT, min: ZScoreBoundT, - start: Union[int, None] = None, - num: Union[int, None] = None, + start: Optional[None] = None, + num: Optional[None] = None, withscores: bool = False, score_cast_func: Union[type, Callable] = float, ): @@ -4794,7 +4794,7 @@ def zscore(self, name: KeyT, value: EncodableT) -> ResponseT: def zunion( self, keys: Union[Sequence[KeyT], Mapping[AnyKeyT, float]], - aggregate: Union[str, None] = None, + aggregate: Optional[str] = None, withscores: bool = False, ) -> ResponseT: """ @@ -4811,7 +4811,7 @@ def zunionstore( self, dest: KeyT, keys: Union[Sequence[KeyT], Mapping[AnyKeyT, float]], - aggregate: Union[str, None] = None, + aggregate: Optional[atr] = None, ) -> ResponseT: """ Union multiple sorted sets specified by ``keys`` into @@ -4843,7 +4843,7 @@ def _zaggregate( command: str, dest: Union[KeyT, None], keys: Union[Sequence[KeyT], Mapping[AnyKeyT, float]], - aggregate: Union[str, None] = None, + aggregate: Optional[str] = None, **options, ) -> ResponseT: pieces: list[EncodableT] = [command] @@ -5994,7 +5994,7 @@ def geoadd( return self.execute_command("GEOADD", *pieces) def geodist( - self, name: KeyT, place1: FieldT, place2: FieldT, unit: Union[str, None] = None + self, name: KeyT, place1: FieldT, place2: FieldT, unit: Optional[str] = None ) -> ResponseT: """ Return the distance between ``place1`` and ``place2`` members of the @@ -6036,14 +6036,14 @@ def georadius( longitude: float, latitude: float, radius: float, - unit: Union[str, None] = None, + unit: Optional[str] = None, withdist: bool = False, withcoord: bool = False, withhash: bool = False, - count: Union[int, None] = None, - sort: Union[str, None] = None, - store: Union[KeyT, None] = None, - store_dist: Union[KeyT, None] = None, + count: Optional[None] = None, + sort: Optional[str] = None, + store: Optional[KeyT] = None, + store_dist: Optional[KeyT] = None, any: bool = False, ) -> ResponseT: """ @@ -6098,12 +6098,12 @@ def georadiusbymember( name: KeyT, member: FieldT, radius: float, - unit: Union[str, None] = None, + unit: Optional[str] = None, withdist: bool = False, withcoord: bool = False, withhash: bool = False, - count: Union[int, None] = None, - sort: Union[str, None] = None, + count: Optional[None] = None, + sort: Optional[str] = None, store: Union[KeyT, None] = None, store_dist: Union[KeyT, None] = None, any: bool = False, @@ -6188,8 +6188,8 @@ def geosearch( radius: Union[float, None] = None, width: Union[float, None] = None, height: Union[float, None] = None, - sort: Union[str, None] = None, - count: Union[int, None] = None, + sort: Optional[str] = None, + count: Optional[None] = None, any: bool = False, withcoord: bool = False, withdist: bool = False, @@ -6263,15 +6263,15 @@ def geosearchstore( self, dest: KeyT, name: KeyT, - member: Union[FieldT, None] = None, - longitude: Union[float, None] = None, - latitude: Union[float, None] = None, + member: Optional[FieldT] = None, + longitude: Optional[float] = None, + latitude: Optional[float] = None, unit: str = "m", - radius: Union[float, None] = None, - width: Union[float, None] = None, - height: Union[float, None] = None, - sort: Union[str, None] = None, - count: Union[int, None] = None, + radius: Optional[float] = None, + width: Optional[float] = None, + height: Optional[float] = None, + sort: Optional[str] = None, + count: Optional[int] = None, any: bool = False, storedist: bool = False, ) -> ResponseT: diff --git a/redis/commands/json/commands.py b/redis/commands/json/commands.py index da879df611..8520fec71b 100644 --- a/redis/commands/json/commands.py +++ b/redis/commands/json/commands.py @@ -15,7 +15,7 @@ class JSONCommands: def arrappend( self, name: str, path: Optional[str] = Path.root_path(), *args: List[JsonType] - ) -> List[Union[int, None]]: + ) -> List[Optional[int]]: """Append the objects ``args`` to the array under the ``path` in key ``name``. @@ -33,7 +33,7 @@ def arrindex( scalar: int, start: Optional[int] = None, stop: Optional[int] = None, - ) -> List[Union[int, None]]: + ) -> List[Optional[int]]: """ Return the index of ``scalar`` in the JSON array under ``path`` at key ``name``. @@ -53,7 +53,7 @@ def arrindex( def arrinsert( self, name: str, path: str, index: int, *args: List[JsonType] - ) -> List[Union[int, None]]: + ) -> List[Optional[int]]: """Insert the objects ``args`` to the array at index ``index`` under the ``path` in key ``name``. @@ -66,7 +66,7 @@ def arrinsert( def arrlen( self, name: str, path: Optional[str] = Path.root_path() - ) -> List[Union[int, None]]: + ) -> List[Optional[int]]: """Return the length of the array JSON value under ``path`` at key``name``. @@ -89,7 +89,7 @@ def arrpop( def arrtrim( self, name: str, path: str, start: int, stop: int - ) -> List[Union[int, None]]: + ) -> List[Optional[int]]: """Trim the array JSON value under ``path`` at key ``name`` to the inclusive range given by ``start`` and ``stop``. @@ -357,7 +357,7 @@ def set_path( return set_files_result - def strlen(self, name: str, path: Optional[str] = None) -> List[Union[int, None]]: + def strlen(self, name: str, path: Optional[str] = None) -> List[Optional[int]]: """Return the length of the string JSON value under ``path`` at key ``name``. From 339d180428715e9439b41d87bcf7c29f6131463d Mon Sep 17 00:00:00 2001 From: kesha1225 Date: Tue, 22 Apr 2025 23:12:33 +0300 Subject: [PATCH 4/9] commit message: fix(redis-client): normalize optional parameter annotations and correct arrtrim return type body: replaced all Union[T, None] = None and bare T = None with Optional[T] = None; changed arrtrim return annotation to Optional[int] --- redis/commands/json/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis/commands/json/commands.py b/redis/commands/json/commands.py index 8520fec71b..d132b93d2c 100644 --- a/redis/commands/json/commands.py +++ b/redis/commands/json/commands.py @@ -89,7 +89,7 @@ def arrpop( def arrtrim( self, name: str, path: str, start: int, stop: int - ) -> List[Optional[int]]: + ) -> Optional[int]: """Trim the array JSON value under ``path`` at key ``name`` to the inclusive range given by ``start`` and ``stop``. From 8df197c5e1b3baee6f7f3a98b13b1f1c04fa2756 Mon Sep 17 00:00:00 2001 From: kesha1225 Date: Sat, 26 Apr 2025 00:06:33 +0300 Subject: [PATCH 5/9] fix(redis-client): replace Optional[None] with Optional[int] for numeric parameters --- redis/commands/core.py | 106 ++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/redis/commands/core.py b/redis/commands/core.py index d250f9e43f..47f88f7c8b 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -92,7 +92,7 @@ def acl_deluser(self, *username: str, **kwargs) -> ResponseT: """ return self.execute_command("ACL DELUSER", *username, **kwargs) - def acl_genpass(self, bits: Optional[None] = None, **kwargs) -> ResponseT: + def acl_genpass(self, bits: Optional[int] = None, **kwargs) -> ResponseT: """Generate a random password value. If ``bits`` is supplied then use this number of bits, rounded to the next multiple of 4. @@ -1304,7 +1304,7 @@ def slaveof( return self.execute_command("SLAVEOF", b"NO", b"ONE", **kwargs) return self.execute_command("SLAVEOF", host, port, **kwargs) - def slowlog_get(self, num: Optional[None] = None, **kwargs) -> ResponseT: + def slowlog_get(self, num: Optional[int] = None, **kwargs) -> ResponseT: """ Get the entries from the slowlog. If ``num`` is specified, get the most recent ``num`` items. @@ -1572,8 +1572,8 @@ def append(self, key: KeyT, value: EncodableT) -> ResponseT: def bitcount( self, key: KeyT, - start: Optional[None] = None, - end: Optional[None] = None, + start: Optional[int] = None, + end: Optional[int] = None, mode: Optional[str] = None, ) -> ResponseT: """ @@ -1641,8 +1641,8 @@ def bitpos( self, key: KeyT, bit: int, - start: Optional[None] = None, - end: Optional[None] = None, + start: Optional[int] = None, + end: Optional[int] = None, mode: Optional[str] = None, ) -> ResponseT: """ @@ -2191,8 +2191,8 @@ def restore( value: EncodableT, replace: bool = False, absttl: bool = False, - idletime: Optional[None] = None, - frequency: Optional[None] = None, + idletime: Optional[int] = None, + frequency: Optional[int] = None, ) -> ResponseT: """ Create a key using the provided serialized value, previously obtained @@ -2360,7 +2360,7 @@ def stralgo( specific_argument: Union[Literal["strings"], Literal["keys"]] = "strings", len: bool = False, idx: bool = False, - minmatchlen: Optional[None] = None, + minmatchlen: Optional[int] = None, withmatchlen: bool = False, **kwargs, ) -> ResponseT: @@ -2960,7 +2960,7 @@ def scan( self, cursor: int = 0, match: Union[PatternT, None] = None, - count: Optional[None] = None, + count: Optional[int] = None, _type: Optional[str] = None, **kwargs, ) -> ResponseT: @@ -2992,7 +2992,7 @@ def scan( def scan_iter( self, match: Union[PatternT, None] = None, - count: Optional[None] = None, + count: Optional[int] = None, _type: Optional[str] = None, **kwargs, ) -> Iterator: @@ -3022,7 +3022,7 @@ def sscan( name: KeyT, cursor: int = 0, match: Union[PatternT, None] = None, - count: Optional[None] = None, + count: Optional[int] = None, ) -> ResponseT: """ Incrementally return lists of elements in a set. Also return a cursor @@ -3045,7 +3045,7 @@ def sscan_iter( self, name: KeyT, match: Union[PatternT, None] = None, - count: Optional[None] = None, + count: Optional[int] = None, ) -> Iterator: """ Make an iterator using the SSCAN command so that the client doesn't @@ -3065,7 +3065,7 @@ def hscan( name: KeyT, cursor: int = 0, match: Union[PatternT, None] = None, - count: Optional[None] = None, + count: Optional[int] = None, no_values: Union[bool, None] = None, ) -> ResponseT: """ @@ -3093,7 +3093,7 @@ def hscan_iter( self, name: str, match: Union[PatternT, None] = None, - count: Optional[None] = None, + count: Optional[int] = None, no_values: Union[bool, None] = None, ) -> Iterator: """ @@ -3121,7 +3121,7 @@ def zscan( name: KeyT, cursor: int = 0, match: Union[PatternT, None] = None, - count: Optional[None] = None, + count: Optional[int] = None, score_cast_func: Union[type, Callable] = float, ) -> ResponseT: """ @@ -3148,7 +3148,7 @@ def zscan_iter( self, name: KeyT, match: Union[PatternT, None] = None, - count: Optional[None] = None, + count: Optional[int] = None, score_cast_func: Union[type, Callable] = float, ) -> Iterator: """ @@ -3177,7 +3177,7 @@ class AsyncScanCommands(ScanCommands): async def scan_iter( self, match: Union[PatternT, None] = None, - count: Optional[None] = None, + count: Optional[int] = None, _type: Optional[str] = None, **kwargs, ) -> AsyncIterator: @@ -3207,7 +3207,7 @@ async def sscan_iter( self, name: KeyT, match: Union[PatternT, None] = None, - count: Optional[None] = None, + count: Optional[int] = None, ) -> AsyncIterator: """ Make an iterator using the SSCAN command so that the client doesn't @@ -3229,7 +3229,7 @@ async def hscan_iter( self, name: str, match: Union[PatternT, None] = None, - count: Optional[None] = None, + count: Optional[int] = None, no_values: Union[bool, None] = None, ) -> AsyncIterator: """ @@ -3258,7 +3258,7 @@ async def zscan_iter( self, name: KeyT, match: Union[PatternT, None] = None, - count: Optional[None] = None, + count: Optional[int] = None, score_cast_func: Union[type, Callable] = float, ) -> AsyncIterator: """ @@ -3489,11 +3489,11 @@ def xadd( name: KeyT, fields: Dict[FieldT, EncodableT], id: StreamIdT = "*", - maxlen: Optional[None] = None, + maxlen: Optional[int] = None, approximate: bool = True, nomkstream: bool = False, minid: Union[StreamIdT, None] = None, - limit: Optional[None] = None, + limit: Optional[int] = None, ) -> ResponseT: """ Add to a stream. @@ -3544,7 +3544,7 @@ def xautoclaim( consumername: ConsumerT, min_idle_time: int, start_id: StreamIdT = "0-0", - count: Optional[None] = None, + count: Optional[int] = None, justid: bool = False, ) -> ResponseT: """ @@ -3595,9 +3595,9 @@ def xclaim( consumername: ConsumerT, min_idle_time: int, message_ids: Union[List[StreamIdT], Tuple[StreamIdT]], - idle: Optional[None] = None, - time: Optional[None] = None, - retrycount: Optional[None] = None, + idle: Optional[int] = None, + time: Optional[int] = None, + retrycount: Optional[int] = None, force: bool = False, justid: bool = False, ) -> ResponseT: @@ -3829,7 +3829,7 @@ def xpending_range( max: StreamIdT, count: int, consumername: Union[ConsumerT, None] = None, - idle: Optional[None] = None, + idle: Optional[int] = None, ) -> ResponseT: """ Returns information about pending messages, in a range. @@ -3883,7 +3883,7 @@ def xrange( name: KeyT, min: StreamIdT = "-", max: StreamIdT = "+", - count: Optional[None] = None, + count: Optional[int] = None, ) -> ResponseT: """ Read stream values within an interval. @@ -3913,8 +3913,8 @@ def xrange( def xread( self, streams: Dict[KeyT, StreamIdT], - count: Optional[None] = None, - block: Optional[None] = None, + count: Optional[int] = None, + block: Optional[int] = None, ) -> ResponseT: """ Block and monitor multiple streams for new data. @@ -3953,8 +3953,8 @@ def xreadgroup( groupname: str, consumername: str, streams: Dict[KeyT, StreamIdT], - count: Optional[None] = None, - block: Optional[None] = None, + count: Optional[int] = None, + block: Optional[int] = None, noack: bool = False, ) -> ResponseT: """ @@ -4000,7 +4000,7 @@ def xrevrange( name: KeyT, max: StreamIdT = "+", min: StreamIdT = "-", - count: Optional[None] = None, + count: Optional[int] = None, ) -> ResponseT: """ Read stream values within an interval, in reverse order. @@ -4030,10 +4030,10 @@ def xrevrange( def xtrim( self, name: KeyT, - maxlen: Optional[None] = None, + maxlen: Optional[int] = None, approximate: bool = True, minid: Union[StreamIdT, None] = None, - limit: Optional[None] = None, + limit: Optional[int] = None, ) -> ResponseT: """ Trims old messages from a stream. @@ -4263,7 +4263,7 @@ def zlexcount(self, name, min, max): """ return self.execute_command("ZLEXCOUNT", name, min, max, keys=[name]) - def zpopmax(self, name: KeyT, count: Optional[None] = None) -> ResponseT: + def zpopmax(self, name: KeyT, count: Optional[int] = None) -> ResponseT: """ Remove and return up to ``count`` members with the highest scores from the sorted set ``name``. @@ -4274,7 +4274,7 @@ def zpopmax(self, name: KeyT, count: Optional[None] = None) -> ResponseT: options = {"withscores": True} return self.execute_command("ZPOPMAX", name, *args, **options) - def zpopmin(self, name: KeyT, count: Optional[None] = None) -> ResponseT: + def zpopmin(self, name: KeyT, count: Optional[int] = None) -> ResponseT: """ Remove and return up to ``count`` members with the lowest scores from the sorted set ``name``. @@ -4418,8 +4418,8 @@ def _zrange( bylex: bool = False, withscores: bool = False, score_cast_func: Union[type, Callable, None] = float, - offset: Optional[None] = None, - num: Optional[None] = None, + offset: Optional[int] = None, + num: Optional[int] = None, ) -> ResponseT: if byscore and bylex: raise DataError("``byscore`` and ``bylex`` can not be specified together.") @@ -4545,8 +4545,8 @@ def zrangestore( byscore: bool = False, bylex: bool = False, desc: bool = False, - offset: Optional[None] = None, - num: Optional[None] = None, + offset: Optional[int] = None, + num: Optional[int] = None, ) -> ResponseT: """ Stores in ``dest`` the result of a range of values from sorted set @@ -4591,8 +4591,8 @@ def zrangebylex( name: KeyT, min: EncodableT, max: EncodableT, - start: Optional[None] = None, - num: Optional[None] = None, + start: Optional[int] = None, + num: Optional[int] = None, ) -> ResponseT: """ Return the lexicographical range of values from sorted set ``name`` @@ -4615,8 +4615,8 @@ def zrevrangebylex( name: KeyT, max: EncodableT, min: EncodableT, - start: Optional[None] = None, - num: Optional[None] = None, + start: Optional[int] = None, + num: Optional[int] = None, ) -> ResponseT: """ Return the reversed lexicographical range of values from sorted set @@ -4639,8 +4639,8 @@ def zrangebyscore( name: KeyT, min: ZScoreBoundT, max: ZScoreBoundT, - start: Optional[None] = None, - num: Optional[None] = None, + start: Optional[int] = None, + num: Optional[int] = None, withscores: bool = False, score_cast_func: Union[type, Callable] = float, ) -> ResponseT: @@ -4674,8 +4674,8 @@ def zrevrangebyscore( name: KeyT, max: ZScoreBoundT, min: ZScoreBoundT, - start: Optional[None] = None, - num: Optional[None] = None, + start: Optional[int] = None, + num: Optional[int] = None, withscores: bool = False, score_cast_func: Union[type, Callable] = float, ): @@ -6040,7 +6040,7 @@ def georadius( withdist: bool = False, withcoord: bool = False, withhash: bool = False, - count: Optional[None] = None, + count: Optional[int] = None, sort: Optional[str] = None, store: Optional[KeyT] = None, store_dist: Optional[KeyT] = None, @@ -6102,7 +6102,7 @@ def georadiusbymember( withdist: bool = False, withcoord: bool = False, withhash: bool = False, - count: Optional[None] = None, + count: Optional[int] = None, sort: Optional[str] = None, store: Union[KeyT, None] = None, store_dist: Union[KeyT, None] = None, @@ -6189,7 +6189,7 @@ def geosearch( width: Union[float, None] = None, height: Union[float, None] = None, sort: Optional[str] = None, - count: Optional[None] = None, + count: Optional[int] = None, any: bool = False, withcoord: bool = False, withdist: bool = False, From f33afac650543241671a3413a8ce44c34d5a6d92 Mon Sep 17 00:00:00 2001 From: kesha1225 Date: Tue, 29 Apr 2025 15:20:35 +0300 Subject: [PATCH 6/9] fix: typo --- redis/commands/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis/commands/core.py b/redis/commands/core.py index 47f88f7c8b..1bd3c2d0ee 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -4811,7 +4811,7 @@ def zunionstore( self, dest: KeyT, keys: Union[Sequence[KeyT], Mapping[AnyKeyT, float]], - aggregate: Optional[atr] = None, + aggregate: Optional[str] = None, ) -> ResponseT: """ Union multiple sorted sets specified by ``keys`` into From 7ee3bf22fa8a08bd530c4ced4bef34c21e7dc5f4 Mon Sep 17 00:00:00 2001 From: kesha1225 Date: Fri, 2 May 2025 22:10:30 +0300 Subject: [PATCH 7/9] commit message: fix(redis-client): fix broken types --- redis/commands/json/commands.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/redis/commands/json/commands.py b/redis/commands/json/commands.py index d132b93d2c..48849e1888 100644 --- a/redis/commands/json/commands.py +++ b/redis/commands/json/commands.py @@ -79,7 +79,7 @@ def arrpop( name: str, path: Optional[str] = Path.root_path(), index: Optional[int] = -1, - ) -> List[Union[str, None]]: + ) -> List[Optional[str]]: """Pop the element at ``index`` in the array JSON value under ``path`` at key ``name``. @@ -89,7 +89,7 @@ def arrpop( def arrtrim( self, name: str, path: str, start: int, stop: int - ) -> Optional[int]: + ) -> List[Optional[int]]: """Trim the array JSON value under ``path`` at key ``name`` to the inclusive range given by ``start`` and ``stop``. @@ -113,7 +113,7 @@ def resp(self, name: str, path: Optional[str] = Path.root_path()) -> List: def objkeys( self, name: str, path: Optional[str] = Path.root_path() - ) -> List[Union[List[str], None]]: + ) -> List[Optional[List[str]]]: """Return the key names in the dictionary JSON value under ``path`` at key ``name``. From 4a7216b0132fd80613a5f7f0b54695bb220a4b39 Mon Sep 17 00:00:00 2001 From: kesha1225 Date: Mon, 5 May 2025 22:07:41 +0300 Subject: [PATCH 8/9] commit message: fix(redis-client): fix broken types --- redis/commands/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis/commands/core.py b/redis/commands/core.py index 1bd3c2d0ee..896ba7471e 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -988,7 +988,7 @@ def select(self, index: int, **kwargs) -> ResponseT: return self.execute_command("SELECT", index, **kwargs) def info( - self, section: Optional[srt] = None, *args: List[str], **kwargs + self, section: Optional[str] = None, *args: List[str], **kwargs ) -> ResponseT: """ Returns a dictionary containing information about the Redis server From 87c07fcd031e6fbd7744f884d305320b775a784c Mon Sep 17 00:00:00 2001 From: kesha1225 Date: Mon, 5 May 2025 22:09:20 +0300 Subject: [PATCH 9/9] commit message: fix(redis-client): fix broken types --- redis/commands/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/redis/commands/core.py b/redis/commands/core.py index 896ba7471e..378898272f 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -190,8 +190,8 @@ def acl_setuser( username: str, enabled: bool = False, nopass: bool = False, - passwords: Optional[str, Iterable[str]] = None, - hashed_passwords: Optional[str, Iterable[str]] = None, + passwords: Optional[Union[str, Iterable[str]]] = None, + hashed_passwords: Optional[Union[str, Iterable[str]]] = None, categories: Optional[Iterable[str]] = None, commands: Optional[Iterable[str]] = None, keys: Optional[Iterable[KeyT]] = None,