API Docs: Add some more precisions about calling __init__ for Blender-derined classes.

Hopefully will avoid confusion like in #134600.
This commit is contained in:
Bastien Montagne
2025-02-17 10:47:39 +01:00
parent 1a071ef755
commit 8ad740ae95

View File

@@ -202,8 +202,14 @@ otherwise Blender's internal initialization won't happen properly:
class AwesomeRaytracer(bpy.types.RenderEngine):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.my_var = 42
...
.. warning::
The Blender-defined parent constructor must be called before any data access to the object, including
from other potential parent types ``__init__()`` functions.
.. warning::
Calling the parent's ``__init__()`` function is a hard requirement since Blender 4.4.
@@ -223,8 +229,9 @@ otherwise Blender's internal initialization won't happen properly:
.. note::
In case you are using complex/multi-inheritance, ``super()`` may not work. It is best then to
explicitly invoke the Blender-defined parent class constructor. For example:
In case you are using complex/multi-inheritance, ``super()`` may not work (as the Blender-defined parent
may not be the first type in the MRO). It is best then to first explicitly invoke the Blender-defined
parent class constructor, before any other. For example:
.. code-block:: python
@@ -232,6 +239,8 @@ otherwise Blender's internal initialization won't happen properly:
class FancyRaytracer(AwesomeRaytracer, bpy.types.RenderEngine):
def __init__(self, *args, **kwargs):
bpy.types.RenderEngine.__init__(self, *args, **kwargs)
AwesomeRaytracer.__init__(self, *args, **kwargs)
self.my_var = 42
...
.. note::