On Mon, 2010-12-20 at 23:05 +0800, Tay Ray Chuan wrote: > On Mon, Dec 20, 2010 at 11:00 PM, Jelmer Vernooij <[email protected]> wrote: > > On Mon, 2010-12-20 at 22:53 +0800, Tay Ray Chuan wrote: > >> _load_file_contents may return a mmap object, so self._contents could be > >> mmap-ed. Close it if so. > >> > >> Note: we use hasattr() instead of isinstance() for pre-Python 2.6 > >> compatibility (mmap became a class in Python 2.6). > > Please use getattr() rather than hasattr() as the latter eats > > exceptions. > > According to the docs, hasattr() wraps around getattr() and "eats" > exceptions raised by the latter, returning False if an exception is > raised, so it should still be fine. The problem is that it doesn't just eat AttributeError but *all* exceptions, including for example KeyboardInterrupt.
try e.g.: if getattr(self._contents, "close", None) is not None: self._contents.close() Cheers, Jelmer
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Mailing list: https://launchpad.net/~dulwich-users Post to : [email protected] Unsubscribe : https://launchpad.net/~dulwich-users More help : https://help.launchpad.net/ListHelp

