Skip to content

Fix A001: rename id shadow variables in jsonrpyc#197

Open
Copilot wants to merge 2 commits intomainfrom
copilot/fix-linter-error-a001
Open

Fix A001: rename id shadow variables in jsonrpyc#197
Copilot wants to merge 2 commits intomainfrom
copilot/fix-linter-error-a001

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

Ruff rule A001 flags local variable assignments that shadow Python built-ins. All five violations were in mcp_servers/codeql/jsonrpyc/__init__.py, where id (a built-in) was used as a local variable name.

Changes

  • Spec.request / Spec.response / Spec.error: Replace the id = json.dumps(id) reassignment pattern with a new encoded_id variable:

    # before
    if isinstance(id, str):
        id = json.dumps(id)
    req += f',"id":{id}'
    
    # after
    encoded_id = json.dumps(id) if isinstance(id, str) else id
    req += f',"id":{encoded_id}'
  • RPC.__call__: Rename the local id variable to req_id throughout the method (assignment, dict lookups, and return value).

  • pyproject.toml: Remove "A001" from [tool.ruff.lint] ignore.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • unsupported.example.com
    • Triggering command: /usr/bin/python python -m pytest tests/ -x -q (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 2, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix linter error A001 and remove it from suppression list Fix A001: rename id shadow variables in jsonrpyc Apr 2, 2026
Copilot AI requested a review from kevinbackhouse April 2, 2026 15:18
@kevinbackhouse kevinbackhouse marked this pull request as ready for review April 2, 2026 15:28
Copilot AI review requested due to automatic review settings April 2, 2026 15:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses Ruff rule A001 by removing local variable assignments that shadow the Python built-in id in the CodeQL JSON-RPC helper, and then tightens linting by un-ignoring A001 in the repo’s Ruff configuration.

Changes:

  • Refactor Spec.request, Spec.response, and Spec.error to avoid reassigning the id parameter (introduce encoded_id).
  • Rename the local id variable to req_id throughout RPC.call.
  • Remove "A001" from Ruff’s ignore list in pyproject.toml.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/seclab_taskflow_agent/mcp_servers/codeql/jsonrpyc/__init__.py Eliminates id shadowing by renaming locals and introducing encoded_id for message building.
pyproject.toml Stops globally ignoring Ruff A001 now that the known violations are addressed.
Comments suppressed due to low confidence (2)

src/seclab_taskflow_agent/mcp_servers/codeql/jsonrpyc/init.py:188

  • Same issue as in request(): only string IDs are JSON-encoded. Because check_id accepts int (and thus bool), a boolean ID would be emitted as True/False here, which is invalid JSON. Prefer encoded_id = json.dumps(id) (or reject bool in check_id) to ensure the response is always valid JSON.
        encoded_id = json.dumps(id) if isinstance(id, str) else id

        # build the response string
        try:
            res = f'{{"jsonrpc":"2.0","id":{encoded_id},"result":{json.dumps(result)}}}'

src/seclab_taskflow_agent/mcp_servers/codeql/jsonrpyc/init.py:237

  • Only string IDs are JSON-encoded before being interpolated into the error JSON. Since check_id allows int (and thus bool), passing True/False as an ID would produce invalid JSON. Encoding IDs with json.dumps(id) unconditionally here (or rejecting bool in check_id) would avoid this edge case.
        encoded_id = json.dumps(id) if isinstance(id, str) else id

        # start building the error string
        err = f'{{"jsonrpc":"2.0","id":{encoded_id},"error":{err_data}}}'

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +151 to +152
encoded_id = json.dumps(id) if isinstance(id, str) else id
req += f',"id":{encoded_id}'
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encoded_id is only JSON-encoded for string IDs, which means a boolean ID (allowed by check_id because bool is a subclass of int) would be rendered as True/False in the JSON output, producing invalid JSON. Consider encoding IDs with json.dumps(id) unconditionally here (or tightening check_id to reject bool) so the emitted JSON is always valid.

This issue also appears in the following locations of the same file:

  • line 184
  • line 234

See below for a potential fix:

            # always JSON-encode the id to ensure valid JSON (e.g. for booleans)
            encoded_id = json.dumps(id)

Copilot uses AI. Check for mistakes.
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.

A001

3 participants