[Python-Dev] py3k: TypeError: object.__init__() takes no parameters

Nick Craig-Wood nick at craig-wood.com
Fri Jan 16 17:53:52 CET 2009


Terry Reedy <tjreedy at udel.edu> wrote:
>  Nick Craig-Wood wrote:
> > I've noticed with latest python 3.1 checkout (68631) if I have this
> > object hierarchy with a default __init__ in the superclass to be used
> > by the subclasses which don't necessarily need an __init__ it blows up
> > with a TypeError.
> > 
> > class Field(object):
> 
>  object is default baseclass, hence not needed

Agreed, but I wanted the code to run with py < 3 also!

> >     def __init__(self, data):
> >         """Default init for the subclasses"""
> >         print("init class=%r, self=%r" % (self.__class__.__name__, self))
> >         super(Field, self).__init__(data)
> 
>  This line is the problem: remove it and I believe all is fine.
>  Since object()s are immutable, its init cannot do anything as far as I 
>  know.  Deleting this is effectively what you did below.

Yes you are absolutely right - that super is never needed.  I don't
know what I was thinking of!  Without that the problem disappears.

[snip]
>  Perhaps 2.5's object.__init__ just swallowed all args, thus hiding bogus 
>  calls.

Yes it did which is the fundamental difference in behaviour between
py2 and py3 as far as I can see.

[snip]
>  Eliminate bad call.

Check!

(Bashes head against wall!)

Thanks

Nick
-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick


More information about the Python-Dev mailing list