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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions