pythonooprenpy

Can't init child class with overloaded __init__ method in Ren'Py python code section


In Ren'Pys python section I've tried to do following:

python:
    class test_class0():
        def __init__(self, **kwargs):
            self.test0 = kwargs['test0']


    class test_class1(test_class0):
        def __init__(self, **kwargs):
            super().__init__(**kwargs)
            self.test1 = kwargs['test1']

    test_obj0 =  test_class0(test0 = 0)
    test_obj1 =  test_class1(test1 = 1, test0 = 0)

This works fine for standalone Python, but with Ren'Py I've got following traceback:

While running game code:
  File "script.rpy", line 62, in script
    python:
  File "script.rpy", line 75, in <module>
    test_obj1 =  test_class1(test1 = 1, test0 = 0)
  File "script.rpy", line 71, in __init__
    super().__init__(**kwargs)
TypeError: super() takes at least 1 argument (0 given)

Solution

  • This error occurs because Ren'Py apparently uses Python 2, where super worked differently than in Python 3 (see Python extending with - using super() Python 3 vs Python 2).

    It seems that support for Python 3 was added in Ren'Py version 8.0.0, which was released on June 26, 2022, so I suggest upgrading.