super bug?

Alex Martelli aleax at aleax.it
Mon Jan 28 11:24:12 EST 2002


"Michal Wallace" <sabren at manifestation.com> wrote in message
news:mailman.1012233824.26238.python-list at python.org...
    ...
> class C(B):
>     def meth(self, arg):
>         super(C, self).meth(arg)
    ...
> >>> class B:
    ...
> >>> class C(B):
> ...     def meth(self, arg):
> ...         super(C, self).meth(arg)
    ...
> TypeError: super() argument 1 must be type, not class
>
>
> Am I misunderstanding the docstring, or is this a bug?

There's a further requirement (not stated outright in the
docstring, so one might frame it as a docstring bug): the
classes involved must derive (directly or indirectly)
from object [i.e. their metaclass must be 'type', i.e.
they must be "new-style classes" and not "classic classes",
i.e. they must be 'types'].

Change just one line of your code, the statement:

class B:

into

class B(object):

or

class B:
  __metaclass__ = type

or insert at module scope before 'class B:' etc the line:

__metaclass__ = type

and your code should work as intended.


Alex






More information about the Python-list mailing list