Bug with super() and reload()?

Thomas Heller theller at python.net
Thu Jan 16 13:19:53 EST 2003


Jp Calderone <exarkun at intarweb.us> writes:

> On Thu, Jan 16, 2003 at 01:48:22PM +0100, Thomas Heller wrote:
> > I stumbled over the following problem with super() and reload().
> > 
> > Consider this module:
> > 
> > [snip code]
> > 
> > prints this traceback:
> > 
> >     Y.test
> >     Traceback (most recent call last):
> >       File "<stdin>", line 8, in ?
> >       File "mod.py", line 8, in test
> >         super(Y, self).test()
> >     TypeError: super(type, obj): obj must be an instance or subtype of type
> > 
> > Thinking hard, I can understand why this traceback occurs: The object
> > 'y' is not an instance of the 'Y' refered to in the source code.
> > 
> > Should this be considered a bug, or is it simply a wart, and reload
> > should be avoided?
> 
>   One could look at it as a wart, though I personally wouldn't.  Regardless,
> it can be worked around.

Anything which needs workarounds is a wart, IMO.

> 
> See twisted.python.rebuild (http://www.twistedmatrix.com) for an example of
> how ;)
> 

Thanks for the pointer, I'll look it up (later, maybe). Twisted
is not yet in my toolbox, although I feel it should be.

The easiest workaround for me is to use the good old
  def test(self):
      print "something"
      X.test(self)

instead of

  def test(self):
      print "something"
      super(Y, self).test()

I'm most happy its not a bug in my code: this occured in the context
of developing inprocess ActiveX controls in ctypes ;-), and first
I was really shocked to see the error message.

Thomas




More information about the Python-list mailing list