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
Low-risk API signature fix with no new logic; omitted arguments behave like empty dict/list at existing guard sites.

Overview
Follow-up to #700: fixes ruff B006 in SemanticRouter by changing five parameters from shared mutable defaults ({} / []) to | None = None.

__init__: connection_kwargs now defaults to None instead of {}; existing connection_kwargs or None when initializing the index keeps behavior the same.

get_route_references / delete_route_references: reference_ids and keys default to None instead of []. Call sites already branch on truthiness (if reference_ids:, if not keys:) and assign lists before iteration, so no extra normalization was added.

Signature-only change; intended to stop cross-call state leaking through shared default objects.

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

@vishal-bala vishal-bala added the auto:internal Changes only affect the internal API label Sep 23, 2026
@vishal-bala

Copy link
Copy Markdown
Collaborator

Hi there, thanks for the PR! Can you update your branch from main? We have a patch to resolve the current CI issue.

…edis#700)

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

Copy link
Copy Markdown
Contributor Author

Done @vishal-bala — rebased onto current main (includes your CI patch). Same five-signature-line change, still normalization-free per the usage audit in the description.

@harshadkhetpal
harshadkhetpal force-pushed the fix/router-mutable-defaults branch from 37a104e to 2b1591f Compare September 27, 2026 10:56

This branch has not been deployed

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

Labels

auto:internal Changes only affect the internal API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants