Fix type hints for spop and srandmember methods#3943
Merged
petyaslavova merged 4 commits intoredis:masterfrom Feb 16, 2026
Merged
Fix type hints for spop and srandmember methods#3943petyaslavova merged 4 commits intoredis:masterfrom
petyaslavova merged 4 commits intoredis:masterfrom
Conversation
The spop() and srandmember() methods were missing Awaitable in their return type hints, causing type errors when used with async Redis clients. Updated both methods to return Union[Awaitable[Union[str, List, None]], str, List, None] to properly support both sync and async usage, matching the pattern used by other set commands like smembers, smismember, and smove. Fixes redis#3886
Contributor
Author
Manual Test ResultsEnvironment
Test 1: Type hints correctly include Awaitable>>> from typing import get_type_hints
>>> from redis.commands.core import SetCommands
>>> hints = get_type_hints(SetCommands.spop)
>>> print(hints['return'])
typing.Awaitable[str | typing.List | None] | str | typing.List | NoneResult: PASS - Test 2: srandmember type hints updated>>> hints = get_type_hints(SetCommands.srandmember)
>>> print(hints['return'])
typing.Awaitable[str | typing.List | None] | str | typing.List | NoneResult: PASS - Test 3: Consistency with other set commands>>> # Verify pattern matches existing commands like smembers, smove
>>> smove_hints = get_type_hints(SetCommands.smove)
>>> 'Awaitable' in str(smove_hints['return'])
True
>>> smembers_hints = get_type_hints(SetCommands.smembers)
>>> 'Awaitable' in str(smembers_hints['return'])
True
>>> # spop and srandmember now follow the same pattern
>>> 'Awaitable' in str(get_type_hints(SetCommands.spop)['return'])
True
>>> 'Awaitable' in str(get_type_hints(SetCommands.srandmember)['return'])
TrueResult: PASS - Test 4: Sync usage unaffected>>> from redis import Redis
>>> # Sync client type annotation still resolves correctly
>>> # (no runtime change, purely a typing fix)Result: PASS - no runtime behavior change, sync usage works as before. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes incorrect type hints for the
spop()andsrandmember()methods that were missingAwaitablein their return types, causing type errors when used with async Redis clients.Changes
spop()return type fromUnion[str, List, None]toUnion[Awaitable[Union[str, List, None]], str, List, None]srandmember()return type fromUnion[str, List, None]toUnion[Awaitable[Union[str, List, None]], str, List, None]These changes align with the pattern used by other set commands like
smembers(),smismember(), andsmove(), which properly support both sync and async usage.Testing
Verified type hints are correctly resolved:
Async usage now works correctly with type checkers:
Fixes #3886