ironpython3
ironpython3 copied to clipboard
object.__init__() takes no parameters in test_inheritance
In IronPython.test_inheritance there are tests which are similar to:
import System
class test(System.Collections.Generic.List[System.Int32]):
def __init__(self):
super().__init__(1)
test()
which fail with:
TypeError: object.__init__() takes no parameters
These tests worked with IronPython 2 and raised a DeprecationWarning. I'm not entirely sure what the purpose of having the super().__init__ calls on a .NET class (which doesn't define __init__). I think having it throw TypeError is correct and the tests should be fixed.
I agree that TypeError in such case is sensible but I think this the whole picture is a little bit trickier.
.NET classes do define __init__ that takes unlimited number of arguments and does nothing, but only if there is no __init__ in the derived class (see the doctext on InstanceOps). I think the reason was to make a smooth and regular Python object construction using the __new__/__init__ progression. But in practice, I see no good reason to call super().__init__ in classes derived from .NET classes. However, from the type system viewpoint, it is inconsistent: I can do:
t = System.Collections.Generic.List[System.Int32](8)
t.__init__(1)
I can also call super().__init__() in class test, but not super().__init__(1) as you have discovered.
Hmm, interesting that instances of .NET types have an __init__ that doesn't appear on the type. Anyway, getting a headache thinking about this so will leave it for the future. 😃
Disabled some tests related to this in https://github.com/IronLanguages/ironpython3/pull/1414