On Wed, Dec 11, 2019 at 1:53 AM Antoon Pardon <antoon.par...@vub.be> wrote: > What would you want to happen in the following case: > > foo1 = Bar() > foo2 = foo1 > del foo1 > > Should the object be cleaned up now or not? >
TBH both are plausible, and to a Python programmer it's immediately obvious that "foo1.close()" should close foo2 as well. Logic doesn't preclude either of them. Imagine if the base object type had a __destroy__() method that would dereference everything the object referenced, clear its __dict__ (if it has one), and causes all attribute access (including methods) to raise DestroyedObjectError. It would be absolutely plausible to call foo1.__destroy__() and have the object actually be destroyed. I know this is plausible because I know of languages that work both ways - that destroying an object actually destroys it immediately, or that explicitly deleting a name binding leaves the object till it's not referenced anywhere. And if there are languages working both ways, it seems a little presumptive to heap scorn on a language designer for either of those options. ChrisA -- https://mail.python.org/mailman/listinfo/python-list