Commit 90736d26 authored by Stefan Behnel's avatar Stefan Behnel

Clarify that extension types which implement "__cinit__" do not require their...

Clarify that extension types which implement "__cinit__" do not require their base types to implement it.
Closes #2809.
parent 782fd480
...@@ -43,9 +43,11 @@ There are two methods concerned with initialising the object. ...@@ -43,9 +43,11 @@ There are two methods concerned with initialising the object.
The :meth:`__cinit__` method is where you should perform basic C-level The :meth:`__cinit__` method is where you should perform basic C-level
initialisation of the object, including allocation of any C data structures initialisation of the object, including allocation of any C data structures
that your object will own. You need to be careful what you do in the that your object will own. You need to be careful what you do in the
:meth:`__cinit__` method, because the object may not yet be fully valid Python :meth:`__cinit__` method, because the object may not yet be a fully valid Python
object when it is called. Therefore, you should be careful invoking any Python object when it is called. Therefore, you should be careful invoking any Python
operations which might touch the object; in particular, its methods. operations which might touch the object; in particular, its methods and anything
that could be overridden by subtypes (and thus depend on their subtype state being
initialised already).
By the time your :meth:`__cinit__` method is called, memory has been allocated for the By the time your :meth:`__cinit__` method is called, memory has been allocated for the
object and any C attributes it has have been initialised to 0 or null. (Any object and any C attributes it has have been initialised to 0 or null. (Any
...@@ -53,12 +55,13 @@ Python attributes have also been initialised to None, but you probably ...@@ -53,12 +55,13 @@ Python attributes have also been initialised to None, but you probably
shouldn't rely on that.) Your :meth:`__cinit__` method is guaranteed to be called shouldn't rely on that.) Your :meth:`__cinit__` method is guaranteed to be called
exactly once. exactly once.
If your extension type has a base type, the :meth:`__cinit__` method of the base type If your extension type has a base type, any existing :meth:`__cinit__` methods in
is automatically called before your :meth:`__cinit__` method is called; you cannot the base type hierarchy are automatically called before your :meth:`__cinit__`
explicitly call the inherited :meth:`__cinit__` method. If you need to pass a modified method. You cannot explicitly call the inherited :meth:`__cinit__` methods, and the
argument list to the base type, you will have to do the relevant part of the base types are free to choose whether they implement :meth:`__cinit__` at all.
initialisation in the :meth:`__init__` method instead (where the normal rules for If you need to pass a modified argument list to the base type, you will have to do
calling inherited methods apply). the relevant part of the initialisation in the :meth:`__init__` method instead, where
the normal rules for calling inherited methods apply.
Any initialisation which cannot safely be done in the :meth:`__cinit__` method should Any initialisation which cannot safely be done in the :meth:`__cinit__` method should
be done in the :meth:`__init__` method. By the time :meth:`__init__` is called, the object is be done in the :meth:`__init__` method. By the time :meth:`__init__` is called, the object is
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment