[Python-ideas] PEP 3155 - Qualified name for classes and functions

Guido van Rossum guido at python.org
Fri Nov 4 21:49:23 CET 2011


On Fri, Nov 4, 2011 at 12:38 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Sun, 30 Oct 2011 09:52:15 +1000
> Nick Coghlan <ncoghlan at gmail.com> wrote:
>> > Example with nested functions
>> > -----------------------------
>> >
>> >>>> def f():
>> > ...   def g(): pass
>> > ...   return g
>> > ...
>> >>>> f.__qname__
>> > 'f'
>> >>>> f().__qname__
>> > 'f.g'
>>
>> For nested functions, I suggest adding something to the qname to
>> directly indicate that the scope is hidden. Adding parentheses to the
>> name of the outer function would probably work:
>>
>>     f().g
>
> I don't know, I find the "()" a bit too smart. I'd like Guido's
> advice on the matter.

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'.

Alternatively perhaps I could live with 'f.<locals>.g' and
'xyzzy.<locals>.f.<locals>.g'.

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.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20111104/2565c725/attachment.html>


More information about the Python-ideas mailing list