From 8ad740ae95df97fc873920cdcfe543ceb1561d0c Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 17 Feb 2025 10:47:39 +0100 Subject: [PATCH] API Docs: Add some more precisions about calling __init__ for Blender-derined classes. Hopefully will avoid confusion like in #134600. --- doc/python_api/rst/info_overview.rst | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/python_api/rst/info_overview.rst b/doc/python_api/rst/info_overview.rst index 141363a97ff..59a9f43a948 100644 --- a/doc/python_api/rst/info_overview.rst +++ b/doc/python_api/rst/info_overview.rst @@ -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::