fix(redisdb): correct kwargs None check in RedisDB.__init__#307
Open
zhouxinfei wants to merge 3 commits intoBoris-code:masterfrom
Open
fix(redisdb): correct kwargs None check in RedisDB.__init__#307zhouxinfei wants to merge 3 commits intoBoris-code:masterfrom
zhouxinfei wants to merge 3 commits intoBoris-code:masterfrom
Conversation
|
@MonkeyCode-AI review 一下 |
|
MonkeyCode-AI 正在分析任务... |
MonkeyCode-AI
left a comment
There was a problem hiding this comment.
我是 MonkeyCode AI 编程助手,你可以在 GitHub 仓库的 PR 中 at @MonkeyCode-AI 来呼唤我。
任务执行细节请参考: https://monkeycode-ai.com
代码审查结果
修复了 RedisDB.__init__ 中对空 kwargs 的判断,使未显式传入连接参数时能够正确回退到 setting.REDISDB_KWARGS,变更合理且低风险。
| 🚨 Critical | 💡 Suggestion | |
|---|---|---|
| 0 | 0 | 1 |
| if service_name is None: | ||
| service_name = setting.REDISDB_SERVICE_NAME | ||
| if kwargs is None: | ||
| if not kwargs: |
There was a problem hiding this comment.
Tip
💡 if not kwargs 会覆盖调用方显式传入的空字典语义(若需要区分“未提供”与“提供但为空”)
当前签名使用 **kwargs,调用方无法传入 None,只能传入若干关键字参数;因此 kwargs 为空通常代表“未提供额外参数”,回退到 setting.REDISDB_KWARGS 是合理的。但如果未来希望支持 RedisDB(**{}) 这类“显式要求不使用默认 kwargs”的语义(尽管当前也等价于没传),if not kwargs 会强制回退到全局默认,无法表达“空覆盖”。这属于产品/接口语义选择问题,不一定要改。
建议: 保持当前实现即可;若要区分语义,可改用显式参数(例如 kwargs: dict | None = None)而不是 **kwargs,并在内部合并/覆盖。
Suggested change
| if not kwargs: |
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.
Description
Fixed the kwargs check in
RedisDB.__init__()fromif kwargs is None:toif not kwargs:.Problem
The original code incorrectly checks
if kwargs is None:, butkwargsis always a dictionary (even if empty) in Python, neverNone. This causes the fallback tosetting.REDISDB_KWARGSto never trigger whenRedisDB()is called without arguments.Solution
Changed the condition to
if not kwargs:which correctly checks for an empty dictionary.Changes Made
if kwargs is None:toif not kwargs: