Skip to content

fix: remove mutable default arguments in SemanticRouter (follow-up to #700) - #737

Open
harshadkhetpal wants to merge 1 commit into
redis:mainfrom
harshadkhetpal:fix/router-mutable-defaults
Open

harshadkhetpal wants to merge 1 commit into
redis:mainfrom
harshadkhetpal:fix/router-mutable-defaults

Conversation

@harshadkhetpal

@harshadkhetpal harshadkhetpal commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #700 (merged last month): extensions/router/semantic.py has the same shared-mutable-default pattern (ruff B006) in code that wasn't covered there:

  • SemanticRouter.__init__(connection_kwargs: dict[str, Any] = {})
  • get_route_references(reference_ids: list[str] = [], keys: list[str] = [])
  • delete_route_references(reference_ids: list[str] = [], keys: list[str] = [])

All five become | None = None. Unlike #700, no normalization statements are needed — I audited every use: __init__ already forwards connection_kwargs or None, and both methods only touch reference_ids/keys behind truthiness guards (if reference_ids:, if not keys: with reassignment before any iteration). So None behaves identically to the old shared {}/[] at every site, and the diff is just the five signature lines.

Testing

python -m py_compile passes; ruff check --select B006 on the file goes from 5 errors to clean.

🤖 Generated with Claude Code


Note

Low Risk
Signature-only fix for shared mutable defaults; call sites already handle None like empty dict/list.

Overview
Follow-up to #700: fixes ruff B006 mutable default arguments on SemanticRouter in semantic.py.

__init__ now takes connection_kwargs as dict[str, Any] | None = None instead of = {}. get_route_references and delete_route_references use reference_ids and keys as list[str] | None = None instead of = [].

No new if x is None: x = ... normalization—the existing connection_kwargs or None forward and truthiness checks on reference_ids/keys already treat omitted args the same as empty collections.

Reviewed by Cursor Bugbot for commit 37a104e. Bugbot is set up for automated code reviews on this repo. Configure here.

…edis#700)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Harshad Khetpal <harshadkhetpal@users.noreply.github.com>
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.

1 participant