Locals window treats attributes referenced in current frame as global variables


Consider this code:
def foo(x):
    return x.imag
Set a breakpoint at return and run it. The Locals window shows two entries; one for x, and one for imag. It should only show one for x.

It happens because the debugger tries to determine any global variables that are used by local frames and include them in the output. It does so by looking at co_names, but co_names includes all names used in the frame, not just variable names. It needs to intersect co_names with globals, and only show those names which are present in both - it's still not 100% accurate, but close enough.