int.__init__ incompatible in Python 3.3

Ulrich Eckhardt ulrich.eckhardt at dominolaser.com
Mon Nov 12 14:48:56 CET 2012


Am 09.11.2012 12:37, schrieb Steven D'Aprano:
> In Python 3.3:
>
> py> class X(int):
> ...     def __init__(self, *args):
> ...         super().__init__(*args)  # does nothing, call it anyway
> ...
> py> x = X(22)
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
>    File "<stdin>", line 3, in __init__
> TypeError: object.__init__() takes no parameters
>
>
> It is apparently an oversight, or a bug, that it ever worked in older
> versions.


I'm not really convinced that the overall behaviour is sound:

py> x = 42
py> x.__init__()
py> x.__init__(1)
py> x.__init__(1,2)
py> x.__init__(1,2,3)
py> x.__init__(1,2,3,4)

Neither of these seem to care about the number and type of parameters. 
On the other hand:

py> y = object()
py> y.__init__()
py> y.__init__(1)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: object.__init__() takes no parameters


So, for some reason that I don't understand yet, my call to the 
superclass' init function skips a class, but only when called with super().


Confused greetings!

Uli



More information about the Python-list mailing list