[Python-Dev] del is not called after creating a new reference (original) (raw)

Nathaniel Smith njs at pobox.com
Mon Mar 20 17:28:42 EDT 2017


On Mar 20, 2017 1:26 PM, "Antoine Pitrou" <solipsis at pitrou.net> wrote:

Hello Oleg,

On Mon, 20 Mar 2017 18:28:29 +0100 Oleg Nesterov <oleg at redhat.com> wrote:

I started to learn python a few days ago and I am trying to understand what del() actually does. https://docs.python.org/3/ reference/datamodel.html says:

object.del(self) ... Note that it is possible (though not recommended!) for the del() method to postpone destruction of the instance by creating a new reference to it. It may then be called at a later time when this new reference is deleted.

This sentence is not technically wrong, but it can easily be misleading. It says "it may then be called at a later time" and probably it should say "it may or may not be called at a later time, depending on the Python implementation you are using".

Modern CPython, and all extant versions of PyPy and Jython, guarantee that del is called at most once. MicroPython doesn't support user-defined del methods.

It's fine if the text wants to leave that open, but the current phrasing is pretty misleading IMO. I also read it as saying that del would be called again if the object is collected again (which may or may not happen). But AFAICT there are actually zero implementations where this is true. Probably worth a small edit :-)

-n -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20170320/a04c4570/attachment.html>



More information about the Python-Dev mailing list