help on autosuper

Michele Simionato mis6 at pitt.edu
Sun Jan 26 13:33:44 EST 2003


Michele Simionato <mis6+ at pitt.edu> wrote in message news:<mailman.1043499885.7817.python-list at python.org>...
> In his essay on type/class unification, Guido defines the following 
> 
> autosuper metaclass:
> 
> --- begin autosup.py ---
> 
> class autosuper(type): #Guido's metaclass
> 
>     def   init  (cls, name, bases, dic):
> 
> super(autosuper, cls).  init  (name, bases, dic)
> 
>     setattr(cls," %s  super" % name, super(cls))
> 
> class C(object): #a simple class
> 
>     metaclass  =autosuper
> 
> --- end autosup.py ---
> 
> Notice that I have put the metaclass in a module called autosup.
> 
> Everything works as expected; however, there is some incompatibility 
> 
> with pydoc:
> 
> >>> import autosup
>  
> >>> help(autosup)
> 
> Traceback (most recent call last):
> 
> File "<pyshell#1>", line 1, in ?
> 
> help(autosup)
> 
> File "C:\PYTHON22\lib\site.py", line 279, in   call  
> 
> return pydoc.help(*args, **kwds)
> 
> File "C:\PYTHON22\lib\pydoc.py", line 1510, in   call  
> 
> self.help(request)
> 
> File "C:\PYTHON22\lib\pydoc.py", line 1546, in help
> 
> else: doc(request, 'Help on %s:')
> 
> File "C:\PYTHON22\lib\pydoc.py", line 1341, in doc
> 
> pager(title % (desc + suffix) + '\n\n' + text.document(thing, name))
> 
> File "C:\PYTHON22\lib\pydoc.py", line 267, in document
> 
> if inspect.ismodule(object): return apply(self.docmodule, args)
> 
> File "C:\PYTHON22\lib\pydoc.py", line 961, in docmodule
> 
> contents.append(self.document(value, key, name))
> 
> File "C:\PYTHON22\lib\pydoc.py", line 268, in document
> 
> if inspect.isclass(object): return apply(self.docclass, args)
> 
> File "C:\PYTHON22\lib\pydoc.py", line 1093, in docclass
> 
> lambda t: t[1] == 'method')
> 
> File "C:\PYTHON22\lib\pydoc.py", line 1035, in spill
> 
> name, mod, object))
> 
> File "C:\PYTHON22\lib\pydoc.py", line 269, in document
> 
> if inspect.isroutine(object): return apply(self.docroutine, args)
> 
> File "C:\PYTHON22\lib\pydoc.py", line 1116, in docroutine
> 
> realname = object.  name  
> 
> AttributeError: 'super' object has no attribute '  name  '
> 
> Somebody can tell me what's happening, please ?
> 
> TIA,
> 
> Michele
> 
> 
> --

It seems that the problem is related to the use of super.
I don't know what pydoc is doing in the example before,
but one can reproduce the same error message in a much
simpler situation:

class C(object):
    "C docstring"
    attr="C.attr"
    meth=lambda self:'C.meth'

class D(C):
    pass

print super(D,D()).attr # C.attr

print super(D,D()).meth() # C.meth

print super(D,D()).__doc__ # C docstring

print C.__name__ #okay

print super(D,D()).__name__ #error!

It seems "super" doesn't work the same for all special attributes: 
it works o.k. for "__doc__" but not for "__name__".
Still I don't know why, i.e. if this is the desired effect or not.

Cheers,

                                  Michele




More information about the Python-list mailing list