Skip to content

Loop variable shadows the dict being iterated in both gradient RPCs #71

Description

@chrislupp

Both gradient RPCs rebind the loop variable over the dict they are iterating:

  • philote_mdo/general/explicit_server.py:129
  • philote_mdo/general/implicit_server.py:325
for jac, value in jac.items():

On the first iteration jac stops being the PairDict of Jacobian blocks and becomes the (name, subname) key tuple.

Why it works today

dict.items() returns a view, and the for statement converts it to an iterator holding its own reference to the underlying dict before the first rebind happens. So the loop completes correctly and the tests pass.

Why it should be fixed

It is a trap for the next reader, and it breaks immediately under any refactor that needs to touch jac again inside or after the loop body — e.g. adding a second pass over the blocks, or referencing jac in an error message.

Fix

Rename the loop variable:

for key, value in jac.items():
    ...
    name=key[0],
    subname=key[1],

Same change in both files.

Activity

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions