[Python-Dev] PEP 442 clarification for type hierarchies

Antoine Pitrou solipsis at pitrou.net
Thu Aug 8 08:30:07 CEST 2013


On Thu, 08 Aug 2013 06:08:55 +0200
Stefan Behnel <stefan_ml at behnel.de> wrote:
> Stefan Behnel, 06.08.2013 18:38:
> > Antoine Pitrou, 06.08.2013 17:49:
> >> Le Tue, 06 Aug 2013 17:18:59 +0200,
> >> Stefan Behnel a écrit :
> >>> If a Python class with a
> >>> __del__ inherits from an extension type that implements
> >>> tp_finalize(), then whose tp_finalize() will be executed first?
> >>
> >> Then only the Python __del__ gets called. It should call
> >> super().__del__() manually, to ensure the extension type's
> >> tp_finalize gets called.
> > 
> > Ok, but then all I have to do in order to disable C level finalisation for
> > a type is to inherit from it and provide an empty __del__ method.
> 
> Oh, and if the Python subtype calls super().__del__() twice, then there is
> no longer a guarantee that the finalisers only get executed once, right?

The guarantee is that the *interpreter* will call __del__ once. You're
free to call it many times yourself, it's just a method.
(but super() itself is supposed to do the right thing, if you're using
it properly)

And, by the way, I'd like to stress again the parallel with __init__:
tp_init can also be called several times if the user calls __init__
manually.

Regards

Antoine.




More information about the Python-Dev mailing list