On Fri, Nov 4, 2011 at 12:38 PM, Antoine Pitrou <<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>> wrote:<br>> On Sun, 30 Oct 2011 09:52:15 +1000<br>> Nick Coghlan <<a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>> wrote:<br>
>> > Example with nested functions<br>>> > -----------------------------<br>>> ><br><span style="font-family: courier new,monospace;">>> >>>> def f():</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">>> > ... def g(): pass</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">>> > ... return g</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">>> > ...</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">>> >>>> f.__qname__</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">>> > 'f'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">>> >>>> f().__qname__</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">>> > 'f.g'</span><br>>><br>>> For nested functions, I suggest adding something to the qname to<br>>> directly indicate that the scope is hidden. Adding parentheses to the<br>
>> name of the outer function would probably work:<br>>><br>>> f().g<br>><br>> I don't know, I find the "()" a bit too smart. I'd like Guido's<br>> advice on the matter.<br>
<br>Hm. Both 'f.g' and 'f().g' for f().__qname__ are misleading, since both look like valid expressions but neither will actually retrieve the intended object. I'd be tempted to return something like '<local in f>.g' where 'f' would be f.__qname__. And yes, if f.__qname__ were '<local in xyzzy>.f', then f().__qname__ should be '<local in <local in xyzzy>.f>.g'.<br>
<br>Alternatively perhaps I could live with 'f.<locals>.g' and 'xyzzy.<locals>.f.<locals>.g'.<br><br>In either case, the use of <...> makes it plain that this should not be taken literally as an expression -- unlike the case of nested classes, where generally 'C.D.E' works to access E, if you have class C containing class D which contains class E.<br>
<br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)<br><br>