Skip to content

fix: rename shadowed variable 'token' to 'result' in search_token tool#135

Open
bigeez wants to merge 2 commits intoOpenGradient:mainfrom
bigeez:fix/search-token-variable-shadowing
Open

fix: rename shadowed variable 'token' to 'result' in search_token tool#135
bigeez wants to merge 2 commits intoOpenGradient:mainfrom
bigeez:fix/search-token-variable-shadowing

Conversation

@bigeez
Copy link
Copy Markdown

@bigeez bigeez commented Apr 4, 2026

Bug

In agent/tools.py, the search_token tool function uses token as both
the input parameter (a str) and the result variable (a TokenMetadata object):

async def search_token(token: str, chain: Optional[str] = None):
    token: Optional[TokenMetadata] = await token_metadata_repo.search_token(token, chain)

This is variable shadowing — the parameter is silently overwritten by the
result. It works by luck (Python evaluates the right side before assignment)
but the type annotation is lying and any future refactor could easily break this.

Fix

Renamed the result variable to result for clarity and correctness.

Related

Similar shadowing issue was fixed in onchain/tokens/metadata.py.

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