Golden Rockefeller schrieb am 09.02.22 um 03:14:
> I would like it if the documentation
> did not state a preference for __cinit__ over __init__
I agree, and I actually hope that it doesn't. But it seems that that's not
clear enough. Apparently, it always says things like
"This is only one of the reasons why the __cinit__() method is safer and
preferable over the normal __init__() method for extension types."
That is correct in the context, but shouldn't read as general as it sounds.
The documentation should explain the differences between the two, and when
to use one or the other.
> "Any initialisation which cannot safely be done
> in the __cinit__() method should be done in the __init__() method."
I think this is very true and important. In general, "__cinit__" should be
used to bring the object into a safe state (so this isn't about speed at
all), and then the rest can be done in "__init__". I'm aware that that's
not quite what the sentence above says or suggests.
> My advice is that, if there has to be a __cinit__ method, it should
> take no parameters, so as not
> to restrict the __init__ method of inherited classes.
It hints at that, but again, probably not clearly enough. Starting with a
no-args "__cinit__" and then see if that's enough seems like a good idea in
general.
The documentation was written incrementally over more than a decade, and
isn't always consistent. Improvements are welcome.
Stefan