Skip to content

Conversation

@majiayu000
Copy link

Summary

Fixes #3712

Update type annotations in Script, AsyncScript, and their corresponding register_script methods to accept both Redis and RedisCluster types.

Changes

  • Added redis.cluster and redis.asyncio.cluster to TYPE_CHECKING imports
  • Updated Script.__init__ to accept Union["redis.client.Redis", "redis.cluster.RedisCluster"]
  • Updated Script.__call__ client parameter similarly
  • Updated ScriptCommands.register_script self type
  • Made equivalent changes for async versions (AsyncScript, AsyncScriptCommands)

Test

Before fix, mypy showed:

Invalid self argument "RedisCluster" to attribute function "register_script" with type "Callable[[Redis, Union[bytes, str, memoryview[int]]], Script]"

After fix, no such error.

🤖 Generated with Claude Code

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>
@jit-ci
Copy link

jit-ci bot commented Dec 10, 2025

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.

@petyaslavova
Copy link
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>
@majiayu000
Copy link
Author

I've proactively added tests for the type hints fix:

  • test_script_with_cluster_client in tests/test_scripting.py: Tests that sync Script class accepts RedisCluster as registered_client
  • test_async_script_with_cluster_client in tests/test_asyncio/test_scripting.py: Tests that AsyncScript class accepts RedisCluster as registered_client

These tests verify that the type hints fix works correctly for both sync and async implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mypy error: Invalid self argument "RedisCluster" to attribute function "register_script"

2 participants