Skip to content

Remove four no-op self-assignments - #2247

Open
Dhairya-007 wants to merge 1 commit into
apache:trunkfrom
Dhairya-007:chore/remove-noop-self-assignments
Open

Dhairya-007 wants to merge 1 commit into
apache:trunkfrom
Dhairya-007:chore/remove-noop-self-assignments

Conversation

@Dhairya-007

Copy link
Copy Markdown

Remove four no-op self-assignments

Description

Four statements of the form x = x, where x is already a local, so each reads the name and writes the same value straight back:

File Line Statement x is
libcloud/common/nttcis.py 2040 mapping = mapping parameter of processor(mapping, name=None)
libcloud/compute/drivers/gridscale.py 367 template = template parameter of _create_volume_from_template(...)
libcloud/compute/drivers/nttcis.py 1356 plan = plan parameter of ex_enable_snapshots(...)
libcloud/storage/drivers/s3.py 989 response = response assigned from result_dict["response"] two lines above

Removing them is behaviour-preserving. There is no scope subtlety hiding here — in all four cases the name is a local before the statement runs, so the assignment cannot be shadowing or capturing anything. They are just lines that cost a reader a moment to rule out as load-bearing.

Why CI never flagged them: the pylint env runs pylint -E, which reports errors only, and self-assigning-variable is W0127 — a warning. So these are invisible to the current gate rather than tolerated by it.

One I deliberately left in place: libcloud/common/cloudstack.py:184 also has a command = command, but there it is the entire body of an if branch that exists specifically to leave command untouched while the sibling branches rewrite it:

if (
    command == "revokesecuritygroupingress"
    and "revokesecuritygroupingressresponse" not in result.object
):
    command = command
elif command == "restorevirtualmachine" and "restorevmresponse" in result.object:
    command = "restorevmresponse"
else:
    command = command + "response"

That one is a placeholder, not dead code, and deleting it would leave an empty block. Happy to turn it into a pass with a short comment if you'd prefer the branch to say what it means, but that felt like a separate judgement call from removing dead lines, so I kept it out of this PR.

Status

Done, ready for review.

Verification

Run with the versions pinned in pyproject.toml's lint group (flake8 5.0.4, black 26.10.1, pylint 4.0.9):

$ flake8 --config ./.flake8 <the four files>
  (clean)

$ black --check <the four files>
All done! 4 files would be left unchanged.

$ pylint -E --load-plugins=pylint_plugins.driver_class --rcfile=./pyproject.toml \
    libcloud/common/ libcloud/storage/ libcloud/compute/
$ echo $?
0

$ pytest libcloud/test/storage/test_s3.py \
         libcloud/test/compute/test_gridscale.py \
         libcloud/test/compute/test_nttcis.py
277 passed, 1 skipped, 9 subtests passed

Checklist (tick everything that applies)

  • Code linting
  • Documentation
  • Tests (existing tests for the touched drivers pass; no new tests, since the change removes statements that have no observable effect)
  • ICLA (not a bigger change)

Claude Code assisted in writing this patch; I checked each statement's scope and ran the linting and tests above before opening it.

Each of these is a statement of the form `x = x` where `x` is already a local
(a parameter in three cases, and a name assigned two lines earlier in the
fourth), so each one reads the name and writes the same value straight back:

- `libcloud/common/nttcis.py:2040`                 `mapping = mapping`
- `libcloud/compute/drivers/gridscale.py:367`      `template = template`
- `libcloud/compute/drivers/nttcis.py:1356`        `plan = plan`
- `libcloud/storage/drivers/s3.py:989`             `response = response`

Removing them is behaviour-preserving. They are the kind of line that costs a
reader a moment to rule out as load-bearing, which is the only reason to
bother.

CI does not flag these because the pylint env runs `pylint -E`, and
self-assigning-variable is W0127, a warning. `pylint -E --rcfile=./pyproject.toml`
passes both before and after this change.

`libcloud/common/cloudstack.py:184` is left alone deliberately: there the
`command = command` is the body of an `if` branch that exists precisely to
leave `command` untouched, so it is a placeholder rather than dead code and
removing it would leave an empty block.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.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