]> granicus.if.org Git - python/commitdiff
Don't write "if self.dict: self.dict.close()"; just write
authorGuido van Rossum <guido@python.org>
Thu, 26 Mar 1998 22:12:22 +0000 (22:12 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 26 Mar 1998 22:12:22 +0000 (22:12 +0000)
"self.dict.close()" and ignore the exception.  The "if self.dict:"
part would be calculated through len(self.dict.keys()), which is very
expensive for a large dictionary...

Lib/shelve.py

index 9b65a0911fa6bd376aca9a613af62008a78b9e5a..6bdc0305dd9e225dc6e896c6312c0fd23408fbb4 100644 (file)
@@ -75,8 +75,7 @@ class Shelf:
        
        def close(self):
                try:
-                       if self.dict:
-                               self.dict.close()
+                    self.dict.close()
                except:
                        pass
                self.dict = 0