[Python-Dev] locals(), closures, and IronPython...

Dino Viehland dinov at exchange.microsoft.com
Mon Mar 5 22:26:19 CET 2007

def a():
                x = 4
                y = 2
                def b():
                                print y, locals()
                print locals()


in CPython prints:

{'y': 2, 'x': 4, 'b': <function b at 0x020726F0>}
2 {'y': 2}

I'm wondering if it's intentional that these don't print dictionaries w/ the same contents or if it's more an accident of the implementation.   In other words would it be reasonable for IronPython to promote all of the locals of a into b's dictionary when both a and b call locals?

We currently match CPython's behavior here - at least in what we display although possibly not in the lifetimes of objects.  We're considering an internal change which might alter the behavior here though and end up displaying all the members.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20070305/9d9e617c/attachment.html 

More information about the Python-Dev mailing list