[Python-3000] PEP: Eliminate __del__

Guido van Rossum guido at python.org
Sat May 12 20:53:58 CEST 2007

On 5/12/07, Steven Bethard <steven.bethard at gmail.com> wrote:
> And here's a version that doesn't lose updates to the finalizer attributes:
>     http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/519635
> It replaces enable_finalizer() with a class attribute __finalattrs__.
> >From __finalize__, all class attributes and methods are accessible, as
> are any instance attributes specified by __finalattrs__. Guido's
> BufferedWriter example looks like::
>     class BufferedWriter(Finalized):
>         __finalattrs__ = 'buffer', 'raw'
>         ...
>         def flush(self):
>             self.raw.write(self.buffer)
>             self.buffer = b""
>         def __finalize__(self):
>             self.flush()

But can I subclass it and in the subclass override (extend) flush()? E.g.

class MyWriter(BufferedWriter):
  def flush(self):
    super(MyWriter, self).flush()  # Or super.flush() once PEP xxx is accepted
    print("Feel free to unplug the disk now")

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-3000 mailing list