From 26f70b361610366de64a160bf49528dcf933ad5f Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Fri, 24 Jun 2022 16:14:43 -0500 Subject: [PATCH] io.mmap: init _bup_closed in __new__, not __init__ So that it's always set during __del__. Otherwise it might not exist if (for example) __new__ or the superclass methods throw an exception before we get to __init__. Signed-off-by: Rob Browning Tested-by: Rob Browning --- lib/bup/io.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/bup/io.py b/lib/bup/io.py index 79a6d83..e2fd410 100644 --- a/lib/bup/io.py +++ b/lib/bup/io.py @@ -22,14 +22,17 @@ class mmap(py_mmap.mmap): that aren't explicitly closed. ''' + def __new__(cls, *args, **kwargs): + result = super().__new__(cls, *args, **kwargs) + result._bup_closed = True # supports __del__ + return result def __init__(self, *args, **kwargs): - self._bup_closed = True # Silence deprecation warnings. mmap's current parent is # object, which accepts no params and as of at least 2.7 # warns about them. if py_mmap.mmap.__init__ is not object.__init__: - super(mmap, self).__init__(self, *args, **kwargs) + super().__init__(self, *args, **kwargs) self._bup_closed = False def close(self): -- 2.39.2