Fix type hints for register_script to support RedisCluster#3876
Open
majiayu000 wants to merge 9 commits intoredis:masterfrom
Open
Fix type hints for register_script to support RedisCluster#3876majiayu000 wants to merge 9 commits intoredis:masterfrom
majiayu000 wants to merge 9 commits intoredis:masterfrom
Conversation
Update type annotations in Script, AsyncScript, and their corresponding register_script methods to accept both Redis and RedisCluster types. This fixes mypy errors when calling register_script on RedisCluster instances. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
Collaborator
|
Hi @majiayu000, thank you for your contribution! We will take a look at it soon. |
Add tests to verify that Script and AsyncScript classes accept RedisCluster as registered_client, validating the type hints fix for register_script to support RedisCluster. - test_script_with_cluster_client: Tests sync Script with RedisCluster - test_async_script_with_cluster_client: Tests AsyncScript with RedisCluster 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Author
|
I've proactively added tests for the type hints fix:
These tests verify that the type hints fix works correctly for both sync and async implementations. |
- Fix ruff format issue in AsyncScriptCommands.register_script by putting Union type hint on single line - Fix test_script_with_cluster_client and test_async_script_with_cluster_client by using bytes script instead of str to avoid MagicMock encoder issue (hashlib.sha1 requires buffer-like object, not MagicMock) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
petyaslavova
requested changes
Dec 16, 2025
Address reviewer feedback: - Remove MagicMock imports (no longer needed) - Replace unit tests using mocks with integration tests marked @pytest.mark.onlycluster - Tests now use real RedisCluster client via the r fixture - Verify register_script actually works by executing the registered script 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
Author
|
Thanks! I moved the import to the top and added onlycluster tests that register and execute scripts using RedisCluster (sync + asyncio). Please take another look. |
The test_xreadgroup_with_claim_min_idle_time test is flaky on PyPy due to timing issues. This empty commit triggers a CI re-run. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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 #3712 #3123
Update type annotations in
Script,AsyncScript, and their correspondingregister_scriptmethods to accept bothRedisandRedisClustertypes.Changes
redis.clusterandredis.asyncio.clusterto TYPE_CHECKING importsScript.__init__to acceptUnion["redis.client.Redis", "redis.cluster.RedisCluster"]Script.__call__client parameter similarlyScriptCommands.register_scriptself typeAsyncScript,AsyncScriptCommands)Test
Before fix, mypy showed:
After fix, no such error.
🤖 Generated with Claude Code